ID, 카테고리 및 값이 포함 된 데이터 프레임이있는 반면, 막대 그래프로 시도 할 때 누락 된 데이터가있는 이벤트 카테고리가 표시되는 별개의 측면에서 카테고리별로 제품이 그룹화 된 수평 도트 플롯을 쉽게 관리 할 수 있습니다.
힌트가 있습니까? 버그입니까 아니면 세부 사항이 누락 되었습니까?
고마워, 마르코.
## I have a data frame with ids, categories, and values
d=data.frame(prd=c("orange","apple","pear","bread","crackers"),
cat=c("fruit","fruit","fruit","bakery","bakery"),
qty=c(10,20,15,8,17)
)
# I manage to have an horizontal dot-plot, with products grouped by category in distinct facets
ggplot(d,aes(y=prd,x=qty)) +
geom_point(stat="identity",size=4) +
geom_segment(aes(yend=prd), xend=0, colour="grey50") +
facet_grid(cat ~ .,scale="free",space="free") +
theme_light()
# though when I try with a barplot, bars, with missing data show up
ggplot(d,aes(x=prd,y=qty)) +
geom_bar(stat="identity") +
coord_flip() +
facet_grid(cat ~ .,scale="free",space="free") +
theme_light()
Ggplot2는 현재 비 직교 coord 또는 coord_flip을 사용하는 무료 스케일을 지원하지 않습니다.
따라서 뒤집지 않고 플로팅 할 수 있습니다.
ggplot(d,aes(y=qty,x=prd)) +
facet_wrap(~cat, scale="free") +
geom_bar(stat="identity") +
theme_light()
또는 뒤집었지만 해결 방법을 사용하십시오. 두 개 중 하나의 범주 형 변수를 만듭니다 (이 솔루션이 시각적으로 그다지 매력적이지 않다는 점을 인정합니다).
d$n <- paste(d$cat, d$prd, sep="|")
ggplot(d,aes(y=qty,x=n)) +
geom_bar(stat="identity") +
coord_flip() +
theme_light()
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다