使用ggplot2绘制选定的列

斯宾塞·特林(Spencer Trinh)

我想绘制多个单独的图,到目前为止,我有以下代码:

但是,我不希望数据集中的最后一列。它使ggplot2绘制x变量与x变量的关系图。

library(ggplot2)
require(reshape)
d <- read.table("C:/Users/trinh/Desktop/Book1.csv", header=F,sep=",",skip=24)
t<-c(0.25,1,2,3,4,6,8,10)
d2<-d2[,3:13] #removing unwanted columns
d2<-cbind(d2,t) #adding x-variable

df <- melt(d2,  id = 't')

ggplot(data=df, aes(y=value,x=t) +geom_point(shape=1) + 
geom_smooth(method='lm',se=F)+facet_grid(.~variable)

我尝试添加

data=subset(df,df[,3:12])

但是我认为我写的不正确。请指教。谢谢。

亚当·奎克(Adam Quek)

以下是使用data(iris)作为示例的方法:

(i)绘制所有变量

 df <- reshape2::melt(iris, id="Species")
 ggplot(df, aes(y=value, x=Species)) + geom_point() + facet_wrap(~ variable)

在此处输入图片说明

(ii)不含“ Petal.Width”的地块

 library(dplyr)
 df2 <- df %>% filter(!variable == "Petal.Width")
 ggplot(df2, aes(y=value, x=Species)) + geom_point() + facet_wrap(~ variable)

在此处输入图片说明

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章