I would like to make boxplots of the following:
Example data:
> head(df2)
Results Capacity Power LDI LDE LB PDC D 1 2 3 4 5 6 7 8 9
1 ImpactDCNoV2GYesDC 1 PG11 LDI6 LDE0 LB0.045 PDC0 D10 1 NA NA NA NA NA NA NA NA
2 ImpactDCNoV2GYesDC 0.95 PG11 LDI5 LDE0 LB0.045 PDC0.25 D10 2 2 6 7 9 NA NA NA NA
3 ImpactDCNoV2GYesDC 0.9 PG11 LDI1 LDE0 LB0.045 PDC0.50 D10 5 3 NA NA NA NA NA NA NA
4 ImpactDCNoV2GYesDC 0.85 PG11 LDI6 LDE0 LB0.045 PDC0.75 D10 8 6 NA 8 NA NA NA NA NA
5 ImpactDCNoV2GYesDC 0.8 PG11 LDI5 LDE0 LB0.045 PDC0 D10 6 NA NA NA NA NA NA NA NA
6 ImpactDCNoV2GYesDC 0.75 PG22 LDI1 LDE0 LB0.045 PDC0 D10 2 NA NA 1 NA NA NA NA NA
I have a large dataset so I decide to loop several plots in order to obtain different plots of other values of PG. Also I use facet_wrap in order to plot the results of the plot over the different values of PDC.
As output I would like to obtain a boxplot of the data in the colums 1 till 9 where the boxplots x-axis are the different values of PDC. and the axis is the value given in the colums 1 till 9.
The code I prepared for this is:
Box.graph <- function(df2, na.rm = TRUE, ...){
Powerlist <- unique(df2$Power)
for (i in seq_along(Powerlist)){
boxplot <-
ggplot(subset(df2, df2$Power==Powerlist[i]),
aes(x =LDI, y = value, colour = variable), group = df2$Power) +
geom_boxplot() +
theme(axis.text.x = element_text(size=14))+
facet_wrap( ~ PDC, ncol =1)+
theme(legend.position = "none")+
scale_y_continuous("LDI")+
scale_x_continuous("Time")+
ggtitle(paste(Powerlist[i], ' Time \n',
"LDI \n",
sep=''))
#save plot as PNG
ggsave(plot = last_plot(), file= paste(StoreResults, '/Results/',
Powerlist[i], "TEST.png", sep=''), scale=2)
print(boxplot)
}
}
#Run the function
Box.graph(df)
But the error that returns is:
Error in eval(expr, envir, enclos) : object 'value' not found
I think the issue is that I don't know how tell R to plot the values of columns 1-9 with the different values of the Capacity.
Can anyone help?