我想在R
中创建一个线图,其中密度在x轴上旋转不同的值假设我有三个密度h1,h2,h3
h1<-rnorm(100); h2<-rnorm(100,2,1); h3<-rnorm(100,5,1);
我想绘制一条线(比如说x1轴上的h1,h2和h3的平均值),并且应该在相应位置的线图上旋转h1,h2和h3的密度图(轴不应该是可见的)
答案 0 :(得分:0)
require(ggplot2)
require(reshape2)
require(plyr)
#reshape into long format; also calculate mean for each group
tmp <- data.frame(h1=rnorm(100), h2=rnorm(100,2,1), h3=rnorm(100,5,1))
ggplot(ddply(melt(tmp),.variables=.(variable),transform,mean=mean(value)),aes(x=mean,y=value,group=variable)) + geom_violin()