두 세트에 대한 통계를 그래프로 표시하는 산점도가 있습니다. 점의 모양은 데이터 포인트가 해당하는 X 축 모집단을 나타내며, 점의 색상은 해당하는 Y 축 모집단을 나타냅니다.
내 테이블은 이렇게 보인다
comp source2 y SEy source1 x SEx color shape
PopA PopAlpha 0.363658 0.002966 PopOne 0.213503 0.002152 green 1
PopB PopAlpha 0.354646 0.002923 PopOne 0.211894 0.002159 green 1
PopC PopAlpha 0.347382 0.002714 PopOne 0.213501 0.00204 green 1
PopA PopBeta 0.231174 0.002729 PopOne 0.213503 0.002152 blue 1
PopB PopBeta 0.228363 0.002614 PopOne 0.211894 0.002159 blue 1
PopC PopBeta 0.227815 0.002481 PopOne 0.213501 0.00204 blue 1
PopA PopAlpha 0.363658 0.002966 PopTwo 0.227151 0.002284 green 8
PopB PopAlpha 0.354646 0.002923 PopTwo 0.225023 0.002247 green 8
PopC PopAlpha 0.347382 0.002714 PopTwo 0.226903 0.002133 green 8
PopA PopBeta 0.231174 0.002729 PopTwo 0.227151 0.002284 blue 8
PopB PopBeta 0.228363 0.002614 PopTwo 0.225023 0.002247 blue 8
PopC PopBeta 0.227815 0.002481 PopTwo 0.226903 0.002133 blue 8
내 코드는 그런
read.table("example.txt", header = TRUE) -> tbl
require(ggplot2)
plot <- ggplot(data = tbl,aes(x = x,y = y)) +
geom_point(colour=tbl$color, mapping=aes(shape=tbl$shape)) +
geom_errorbar(aes(ymin = y-SEy,ymax = y+SEy,width=0),colour=tbl$color) +
geom_errorbarh(aes(xmin = x-SEx,xmax = x+SEx,height=0),colour=tbl$color) +
geom_abline(intercept = 0, slope = 1) + scale_shape_identity()
#+ scale_colour_manual(name = "Y population",labels = c("PopAlpha", "PopBeta"),values = c("green", "blue"))
#+ scale_shape_manual(name = "X population",labels = c("PopOne","PopTwo"),values = c(1,8))
ggsave(plot=plot,height=6,width=7, filename="example2.pdf", useDingbats=FALSE)
plot(plot)
dev.off()
범례 줄의 주석 처리를 제거하려고하면 "Error in + scale_shape_manual (name ="Xpopulation ", labels = c ("PopOne ", : invalid argument to unary operator"가 표시됨)
이건 전설없는 내 줄거리
누군가 내가 뭘 잘못하고 있는지 알아낼 수 있습니까? 감사!
한 부분은 색을 나타내고 다른 부분은 모양을 나타내는 범례가 필요합니다. 내 실제 데이터 세트에는 4 가지 색상과 7 가지 모양이 있으므로 모든 조합을 설명하는 범례를 가질 수 없습니다.
structure(list(comp = structure(c(1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L), .Label = c("PopA", "PopB", "PopC"), class = "factor"), source2 = structure(c(1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L), .Label = c("PopAlpha", "PopBeta"), class = "factor"), y = c(0.363658, 0.354646, 0.347382, 0.231174, 0.228363, 0.227815, 0.363658, 0.354646, 0.347382, 0.231174, 0.228363, 0.227815), SEy = c(0.002966, 0.002923, 0.002714, 0.002729, 0.002614, 0.002481, 0.002966, 0.002923, 0.002714, 0.002729, 0.002614, 0.002481), source1 = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("PopOne", "PopTwo"), class = "factor"), x = c(0.213503, 0.211894, 0.213501, 0.213503, 0.211894, 0.213501, 0.227151, 0.225023, 0.226903, 0.227151, 0.225023, 0.226903), SEx = c(0.002152, 0.002159, 0.00204, 0.002152, 0.002159, 0.00204, 0.002284, 0.002247, 0.002133, 0.002284, 0.002247, 0.002133), color = structure(c(2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L), .Label = c("blue", "green"), class = "factor"), shape = c(1L, 1L, 1L, 1L, 1L, 1L, 8L, 8L, 8L, 8L, 8L, 8L)), .Names = c("comp", "source2", "y", "SEy", "source1", "x", "SEx", "color", "shape"), class = "data.frame", row.names = c(NA, -12L))
다음 줄의 시작보다는 줄 끝에 +가 있어야합니다.
ggplot(data = tbl,aes(x = x,y = y)) +
geom_point(colour=tbl$color, mapping=aes(shape=tbl$shape)) +
geom_abline(intercept = 0, slope = 1) + scale_shape_identity()
지금까지의 코드는 구문 적으로 완전합니다. 따라서 다음 줄은 이전 줄에 추가되지 않고 함께 추가 된 것으로 간주됩니다.
+ scale_colour_manual(name = "Y population",labels = c("PopAlpha", "PopBeta"),values = c("green", "blue"))
+ scale_shape_manual(name = "X population",labels = c("PopOne","PopTwo"),values = c(1,8))
+ s를 이전 줄의 끝으로 이동하면 줄이 완성되지 않습니다.
ggplot2가 나올 때마다이 실수를합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다