如下所述,该数据框架由4个方法和每个方法的3个性能度量组成。我希望每个方法都有一个条形图,如下所示:

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然而,我不能用ggplot或类似的东西来获得它。有人能帮我吗?
发布于 2016-08-05 20:24:10
首先读取您的数据
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)接下来,我们需要使用reshape2对数据框进行整形,使其对ggplot2友好
dd_m = reshape2::melt(dd, c("Method"))
head(dd_m, 2)
# Method variable value
#1 Baseline MSE 42675
#2 LinearRegression MSE 10739然后我们使用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

https://stackoverflow.com/questions/38789028
复制相似问题