简体   繁体   中英

Create dotplot in R, with two values (dots) on each y-axis (observation)

I would like to create a dotplot in R, such that the y-axis is the observations, and the x-axis is the time. I have two time points per observation, and hence, would like two dots per observation, connected by a line, if possible.

I cannot get this to work in R, although I can get one dot per observation:

N=10
time1 = runif(N, min=0, max=100)
time2 = runif(N, min=0, max=100)
DF=data.frame(name=letters[1:10],t1=time1,t2=time2)
dotchart(DF$t1,labels=name,cex=.7)

If you have any advice, please let me know. Thank you!

Here's one method using ggplot2 :

time1 <- runif(N, min=0, max=100)
time2 <- runif(N, min=0, max=100)

DF2 <- data.frame(name = rep(letters[1:10], 2),
                  time = c(time1, time2))

library(ggplot2)
qplot(data=DF2, x=time, y=name, group=factor(name), geom=c("point", "line"))  

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM