Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用R绘图在R中进行点绘图_R_Plot - Fatal编程技术网

使用R绘图在R中进行点绘图

使用R绘图在R中进行点绘图,r,plot,R,Plot,最好使用标准R图(不是ggplot)和2x2数据帧生成具有两个类似因子的点图,最佳方法是什么。水平线应该是手段。我试过克利夫兰点图,但不知道如何获得两个数据系列,并使点抖动: 下面的代码应该可以做到这一点: set.seed(1) t1 = rnorm(10); t2 = rnorm(10, 2) t1_g2 = rnorm(10, 4);t2_g2 = rnorm(10) ##Don't print the axes labels par(ann=FALSE) ##Plot first s

最好使用标准R图(不是ggplot)和2x2数据帧生成具有两个类似因子的点图,最佳方法是什么。水平线应该是手段。我试过克利夫兰点图,但不知道如何获得两个数据系列,并使点抖动:


下面的代码应该可以做到这一点:

set.seed(1)
t1 = rnorm(10); t2 = rnorm(10, 2)
t1_g2 = rnorm(10, 4);t2_g2 = rnorm(10)

##Don't print the axes labels
par(ann=FALSE)

##Plot first set of data.
##Need to check for sensible ranges
##Use the jitter function to spread data out.
plot(jitter(rep(0,10),amount=0.2), t1,
     xlim=range(-0.5,3.5), ylim=range(-3,8),
     axes=FALSE,frame.plot=TRUE)
points(jitter(rep(1,10), amount=0.2), t1_g2, col=2)
points(jitter(rep(2,10), amount=0.2), t2)
points(jitter(rep(3,10), amount=0.2), t2_g2, col=2)

##Add in the y-axis
axis(2, seq(-4,8,by=2))

##Add in the x-axis labels
mtext("Treatment 1", side = 1, at=0.5)
mtext("Treatment 2", side = 1, at=2.5)

##Add in the means
segments(-0.25, mean(t1), 0.25, mean(t1))
segments(0.75, mean(t1_g2), 1.25, mean(t1_g2))
segments(1.75, mean(t2), 2.25, mean(t2))
segments(2.75, mean(t2_g2), 3.25, mean(t2_g2))

##Add in the legend
legend(0, 8, c("Group 1", "Group 2"), col=1:2, pch=1)
其中:


您可以向我们展示您的尝试(这样Q听起来就不会像“为我工作”)。我们也不介意使用一些虚假数据。那么ggplot和/或lattice有什么不好呢?学习一些新功能可能需要一点时间,但从长远来看,你的图表制作会容易得多。