ggplot2
데이터의 부분 집합 플롯
수색…
통사론
- xlim (left.limit, right.limit)
- data.frame [data.frame $ variable == "desired.variable",]
xlim / ylim 사용
> library(ggplot2)
> ggplot(iris,aes(Sepal.Width)) + geom_density() + xlim(1,3.5)
xlim 또는 ylim을 사용하면 플롯이 잘리지 않으며, ggplot은 stat 함수 (이 경우에는 stat_density)를 호출하기 전에 데이터를 부분 집합합니다. 경고 메시지에서이를 볼 수 있습니다.
Warning message:
Removed 19 rows containing non-finite values (stat_density).
범주 형 변수에 대한 인라인 하위 집합
ggplot(iris[iris$Species == "setosa",],aes(Sepal.Width)) +
geom_density()
여기서는 ggplot에 전달하기 전에 데이터 프레임을 하위 집합으로 지정합니다. 데이터 프레임 데이터 구조에서 파생 된 매우 유용한 도구입니다.
코드를 읽기 쉽게하기 위해 dplyr 의 filter 사용할 수도 있습니다.
library(dplyr)
iris %>% filter(Species == "setosa") %>% ggplot(aes(Sepal.Width)) +
geom_density()
Modified text is an extract of the original Stack Overflow Documentation
아래 라이선스 CC BY-SA 3.0
와 제휴하지 않음 Stack Overflow