Reputation: 127
I want to join a multiple dataframe, so I can make a multiple boxplot in one graph as Plot multiple boxplot in one graph. However, my data has a different format, I need to convert to table then I will use a "left_join" and then a "melt" function before plotting. I got an error "Error in alloc.col(ans) : object 'Csetmutable' not found" and couldn't find the way how to fix it. Please show me if there is other way to make a plot without converting to table. Thank you for your help.
library("reshape2")
library("ggplot2")
library("dplyr")
library(data.table)
df<-data.frame(T = c(25, 25, 85, 85, 125, 125, 125), V =c(1.03, 1.06, 1.56,1.75,1.82, 1.85, 1.90), type=c(2,2,2,2,2,2,2))
df1<-data.frame(T = c(25, 85, 85, 85, 85, 125, 125), V =c(1.13, 1.17, 1.66,1.76,1.89, 1.90, 1.95), type=c(5,5,5,5,5,5,5))
df2<-data.frame(T = c(25, 25, 25, 85, 125, 125), V =c(1.03, 1.06, 1.56,1.75,1.82, 1.85), type=c(7,7,7,7,7,7))
df.t2 <-select(df,c("T","V"))
names(df.t2)[2]<- "type2"
df.t5 <-select(df1,c("T","V"))
names(df.t5)[2]<- "type5"
df.t7 <-select(df2,c("T","V"))
names(df.t7)[2]<- "type7"
df.t2 = as.data.table(df.t2) # give an error
df.t5 = as.data.table(df.t5)
df.t7 = as.data.table(df.t7)
df.plot <- left_join(df.t2, df.t5,by="T",all=TRUE)
Upvotes: 0
Views: 332
Reputation: 7312
You don't need the data.table
bits at all.
require(plyr)
First, combine everything into one data frame:
main <- rbind(df,df1,df2)
Then rename your type levels
main$type <- as.factor(main$type)
main <- transform(main, type = revalue(type,c("2"="type2", "5"="type5", "7" = "type7")))
main$T <- as.factor(main$T)
Finally, plot mapping type
as your x-axis variable and V
as your y-axis variable.
g1 <-ggplot(main, aes(type, V))+geom_boxplot(aes(color=T),size=1.1)
Upvotes: 1