Spencer Trinh
Spencer Trinh

Reputation: 783

plot selected columns using ggplot2

I would like to plot multiple separate plots and so far I have the following code:

However, I don't want the final column from my dataset; it makes ggplot2 plot x-variable vs x-variable.

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)

I tried adding

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

but I don't think I am writing it correctly. Please advise. Thanks.

Upvotes: 0

Views: 2782

Answers (1)

Adam Quek
Adam Quek

Reputation: 7153

Here's how you could do it, using data(iris) as an example:

(i) plot with all variables

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

enter image description here

(ii) plot without "Petal.Width"

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

enter image description here

Upvotes: 2

Related Questions