[英]Plot 3 categories of dots with single x axis scale - R ggplot2
我想想像一下序列的长度如何影响不同类别中的错误数量。
问题实际上是从文件格式开始的,但是文件的格式如下:
category count length
s 12 1500
i 13 1500
d 15 1500
s 17 1600
i 18 1600
d 22 1600
s 14 1500
i 15 1500
d 17 1500
s 30 1800
i 40 1800
d 0 1800
我如何绘制此图以使长度列为x轴,s,i,d为不同颜色或形状的点。
我不确定您为什么接受上述答案,因为您已明确要求ggplot2。 所以我添加ggplot解决方案以防万一
library(ggplot2)
test <- data.frame(category = factor(c("s","i","d","s","i","d","s","i","d","s","i","d")),
count = c(12,13,15,17,18,22,14,15,17,30,40,0),
length = c(1500,1500,1500,1600,1600,1600,1500,1500,1500,1800,1800,1800))
ggplot(test, aes(x = length, y = count)) + geom_point(aes(colour = category))
也许这可行:
xx = read.table("/tmp/tmp.txt", sep=" ", header=TRUE)
yy = split(xx[c("count", "length")], xx[["category"]])
with(yy[["d"]],
plot(y=count, x=length,
xlim=c(min(xx[["length"]]), max(xx[["length"]])),
ylim=c(min(xx[["count"]]), max(xx[["count"]])),
col="red"))
with(yy[["i"]], points(y=count, x=length, col="blue"))
with(yy[["s"]], points(y=count, x=length, col="green"))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.