반응형
ggplot2의 두 열로 그룹화
두 개의 열로 그룹화할 수 있습니까?따라서 교차 제품은 다음에 의해 그려집니다.geom_point()그리고.geom_smooth()?
예:
frame <- data.frame(
series <- rep(c('a', 'b'), 6),
sample <- rep(c('glass','water', 'metal'), 4),
data <- c(1:12))
ggplot(frame, aes()) # ...
그 점들이6그리고.12그룹을 공유하지만 그룹과 공유하지 않음3.
이 질문에서 예를 들어, 사용interaction두 열을 새 요인으로 결합하는 방법
# Data frame with two continuous variables and two factors
set.seed(0)
x <- rep(1:10, 4)
y <- c(rep(1:10, 2)+rnorm(20)/5, rep(6:15, 2) + rnorm(20)/5)
treatment <- gl(2, 20, 40, labels=letters[1:2])
replicate <- gl(2, 10, 40)
d <- data.frame(x=x, y=y, treatment=treatment, replicate=replicate)
ggplot(d, aes(x=x, y=y, colour=treatment, shape = replicate,
group=interaction(treatment, replicate))) +
geom_point() + geom_line()

예:
qplot(round, price, data=firm, group=id, color=id, geom='line') +
geom_smooth(aes(group=interaction(size, type)))
왜 그냥paste두 개의 열을 함께 사용하고 그 변수를 그룹으로 사용합니까?
frame$grp <- paste(frame[,1],frame[,2])
이를 위한 좀 더 공식적인 방법은 기능을 사용하는 것입니다.interaction.
언급URL : https://stackoverflow.com/questions/9968976/group-by-two-columns-in-ggplot2
반응형
'programing' 카테고리의 다른 글
| 플라스크에서 CORS를 활성화하는 방법 (0) | 2023.06.16 |
|---|---|
| MariaDB/MySQL : SQLite3에서 Attach DATABASE와 유사한 명령이 있습니까? (0) | 2023.06.16 |
| vb.net 의 사전에서 어떻게 반복할 수 있습니까? (0) | 2023.06.16 |
| 명령행에서 TypeScript 코드의 구문 오류를 확인하는 방법은 무엇입니까? (0) | 2023.06.16 |
| "이 시스템에서 스크립트 실행이 사용되지 않도록 설정되어 있으므로 Firebase를 로드할 수 없습니다.", 윈도우즈의 VSCode (0) | 2023.06.16 |