Reputation: 59
I have a dataframe like:
X1 X2 X3 ...
Title One Two Three
X1 0 10 19
X2 4 20 3
X3 17 39 3
..
I would like to create a Boxplots with the title of it being 'Title' (one, two or three) and the corresponding data in each column being used. So, I want a Boxplot for each column. How can I do this?
The Y-axis is X1, X2... (in the leftmost column) (which should just be 1, 2..) and the x-axis is the Title.
Upvotes: 0
Views: 8815
Reputation: 2541
df <- data.frame(
'One' = c( 0, 4, 17),
'Two' = c(10, 20, 39),
'Three' = c(19, 3, 3))
lapply(seq_along(df), function(x){
boxplot(df[[x]], main = paste("Title", colnames(df))[[x]])
})
Upvotes: 0
Reputation: 6073
In base R:
df <- data.frame(
'One' = c( 0, 4, 17),
'Two' = c(10, 20, 39),
'Three' = c(19, 3, 3))
boxplot(df, main="My Title")
Upvotes: 2
Reputation: 1015
library(reshape2)
library(ggplot2)
x <- data.frame('One' = c(0, 4, 17), 'Two' = c(10, 20, 39), 'Three' = c(19, 3, 3))
x <- melt(x)
plt <- ggplot(data = x, aes(x = variable, y = value))
plt + geom_boxplot() + theme_minimal() + labs(x = "Title", y = "x")
Upvotes: 5