ggplot
및 로 막대 그림을 그리고 geom_bar
싶지만의 동작이 geom_bar
일치하지 않는 것 같습니다 . 이유를 모르겠습니다.
내 데이터는 강수량의 시계열입니다.
library(ggplot2)
library(data.table)
library(lubridate)
set.seed(42)
dt1 <- data.table(dateHeure=seq(ymd_hms("2014-06-04 13:30:00"),
ymd_hms("2014-10-20 08:30:00"), by='1 hour'),
rain=sample(c(rep(5,15), rep(10,15), rep(20,10),
rep(30, 5), 40, rep(0, 3262))))
그런 다음 플롯했는데 모든 데이터가 표시되지는 않습니다. 일부 데이터가 누락 된 이유는 무엇입니까?
ggplot(data=dt1)+
geom_bar(aes(x=dateHeure, y=rain),
stat="identity",
fill="blue") # doesn't work!
그러나에 변수 color
를 추가 aes
하면 플롯이 정확합니다!
ggplot(data=dt1)+
geom_bar(aes(x=dateHeure, y=rain, color="rain"),
stat="identity",
width=0.2) # work properly
그래서 누군가가 왜 geom_bar
제대로 작동하지 않는지 알고 color
있습니까? 때로는 모든 데이터가 올바르게 표시되지 않으면 믿을 수 없기 때문에 ...
감사!
edit: to respond to @eipi10, i added the plots. The strange thing is that when i resize the plot window in the first case, the data which is plotted changes!
Based on the edit to your question, I think I know what's happening: In the first plot, you use fill="blue"
. But the bin widths are very small compared to the overall range of the x-axis. This results in very, very thin vertical bars--so thin that you can't see some of them on your screen, but they appear when you expand the physical width of the plot.
On the other hand, in your second plot you used colour="rain"
, which adds a border to each bar, making each bar thicker, so they are visible, even when the physical width of the plot is relatively small.
colour="blue"
첫 번째 플롯에 추가 (또는 "빨간색"또는 기타)를 시도하면 크기를 조정하지 않아도 모든 막대가 표시 될 것입니다. 반면 에 두 번째 플롯에서로 변경 colour="rain"
하고 fill="rain"
두 번째 플롯에서 "데이터 사라짐"효과를 생성하는지 확인하십시오.
업데이트 : 귀하의 의견에 대한 응답으로 색상 매개 변수를 사용한 다음 원하는 막대 두께를 정확하게 얻기 위해 선 너비를 설정할 수 있으므로 실제로 필요하지 않습니다 fill
. 예를 들면 :
ggplot(data=dt1)+
geom_bar(aes(x=dateHeure, y=rain),
stat="identity",
colour="blue", lwd=0.5)
lwd
원하는 막대 너비를 제공하는 값으로 (선 너비)를 설정하십시오 . 물론 색상도 변경할 수 있습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다