簡體   English   中英

用單個x軸刻度繪制3類點-R ggplot2

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM