r - R中倾斜箱线图的x标签

标签 r ggplot2 boxplot

我试图寻找一种方法来倾斜我的箱线图,但从未找到正确的名称位置。

我有每个模型不同精度的数据框Accuracy,我想在箱线图中显示变异性。

  sample iteration poly_eps.001_C1 poly_eps.01_C1 poly_eps.1_C1 poly_eps.001_C10 poly_eps.01_C10
(int)     (int)           (dbl)          (dbl)         (dbl)            (dbl)           (dbl)
    1         1       0.9841270      0.9841270     0.9761905        0.9761905       0.9761905
    1         2       0.9680000      0.9680000     0.9520000        0.9600000       0.9600000
    1         3       0.9523810      0.9523810     0.9603175        0.9365079       0.9365079
    1         4       0.9600000      0.9600000     0.9600000        0.9520000       0.9520000
    1         5       0.9523810      0.9523810     0.9682540        0.9444444       0.9444444

然后我的代码

     # algorithms helpsvme only getting the desired features for the boxplot
  algorithms = names(accuracies_table[-c(1:2)])  

  boxplot(accuracies_table[algorithms], col = color ,
      main = "Polynomial KSVM Models", ylab = "Accuracy",
      las=2,ylim = c(0.90,1))

enter image description here

有人可以帮我倾斜 x 轴标签吗?或者如何在 ggplot2 中完成此操作?

最佳答案

试试这个:

library(ggplot2)
library(reshape2)
df <- melt(accuracies_table[algorithms])
ggplot(df, aes(variable, value, fill=variable)) + geom_boxplot() +
        ggtitle("Polynomial KSVM Models") + ylab("Accuracy") +
  theme(axis.text.x = element_text(angle = 45, size=15, hjust = 1))

enter image description here

关于r - R中倾斜箱线图的x标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39840603/

相关文章:

r - 将水平分位数线添加到散点图 ggplot2 R

r - 如何在不同的ggplot类型之间切换?

r - 如何在 R 中数据操作之前和之后使用 ggplot for ggarrange 绘制 "persistent"绘图

r - ggplot geom_jitter 落后于(多个)geom_boxplot

r - 使用knitr生成复杂的动态文档

r - 如何使用 R Markdown 在 html 输出中创建动画

python - 从 Seaborn Boxplot 中提取异常值

r - R图中出现的奇怪线条

r - 解释 R Mclust 包的结果

根据多个条件删除组上的行 r