Reputation: 91
This dataframe as explained below consists of 4 methods and 3 performance measures for each method. I want to have a barplot for each method similar as this:
Method MSE RMSE MAE
Baseline 42674.68 206.58 149.96
Linear Regression 10738.56 103.63 55.85
Random forest 4492.47 67.03 37.29
Neural Network 7650.72 87.47 57.50
However, I am not able to obtain this with ggplot or something similar. Can someone help me?
Upvotes: 0
Views: 3339
Reputation: 60522
First read in your data
dd = read.table(textConnection("Method MSE RMSE MAE
Baseline 42674.68 206.58 149.96
LinearRegression 10738.56 103.63 55.85
Randomforest 4492.47 67.03 37.29
NeuralNetwork 7650.72 87.47 57.50"), header=TRUE)
Next we need to reshape your data frame to be ggplot2 friendly using reshape2
dd_m = reshape2::melt(dd, c("Method"))
head(dd_m, 2)
# Method variable value
#1 Baseline MSE 42675
#2 LinearRegression MSE 10739
Then we use geom_bar
library(ggplot2)
ggplot(dd_m) +
geom_bar(aes(x=variable, y=value, fill=Method),
stat="identity", # Don't transform the data
position = "dodge") # Dodge the bars
Upvotes: 1