Niklas
Niklas

Reputation: 131

Boxplots in ggplot2 R

My goal is to visualize some data frames with ggplot2.

I have several data.frames looking like this

enter image description here

And my goal is a boxplot looking like this, just nicer.

enter image description here

I managed to get single boxplots using

plt <- ggplot(data, aes(RF, data$RF)) +
  geom_boxplot()
plt

But that's not what I want.

Upvotes: 0

Views: 2092

Answers (3)

floodking
floodking

Reputation: 277

I guess this is what you want:

library(ggplot2)
library(reshape)
myddt_m = melt(mydata)
names(myddt_m)=c("Models","CI")
ggplot(myddt_m, aes(Models, CI,fill=Models )) + geom_boxplot()+guides(fill=FALSE)+labs( x="", y="C-Index")

The resulting image

Upvotes: 2

Sidhha
Sidhha

Reputation: 268

library(ggplot2)
library(reshape)
airquality_m = melt(airquality)
ggplot(airquality_m, aes(variable, value )) + geom_boxplot() 

I did not beautify the plot but I guess you get the idea here.

enter image description here

Upvotes: 3

Koundy
Koundy

Reputation: 5555

That boxplot you showed is created with base-r graphics. Single command

boxplot(data) will do it.

If you want to use ggplot, you have to first melt the dataframe and then plot.

library(reshape2)
datPlot <- melt(data)
ggplot(datPlot,aes(variable,value)) + geom_boxplot()

Upvotes: 3

Related Questions