R 箱线图两个框的一个x轴标记标签
我试图在R中使用ggplot2创建一个箱线图,下面是我的代码和它生成的图。我想改变它,所以我不想让x轴标记为0.5mg,0.5mg,1mg,1mg,2mg和2mg,我只想在两组方框图之间分别标记0.5mg,1mg和2mg。有没有办法做到这一点 结果:R 箱线图两个框的一个x轴标记标签,r,ggplot2,R,Ggplot2,我试图在R中使用ggplot2创建一个箱线图,下面是我的代码和它生成的图。我想改变它,所以我不想让x轴标记为0.5mg,0.5mg,1mg,1mg,2mg和2mg,我只想在两组方框图之间分别标记0.5mg,1mg和2mg。有没有办法做到这一点 结果: ggplot(ToothGrowth, aes(x=interaction(supp, dose), y=len, fill=supp)) + geom_boxplot() + scale_x_discrete(labels = c("0.5
ggplot(ToothGrowth, aes(x=interaction(supp, dose), y=len, fill=supp)) +
geom_boxplot() +
scale_x_discrete(labels = c("0.5mg", "0.5mg", "1mg", "1mg", "2mg", "2mg"), name = "Dosage") +
scale_y_continuous(name = "Tooth Length") +
scale_fill_discrete(name = "Supplement",
labels = c("Orange Juice", "Ascorbic Acid"))
library(ggplot2)
ggplot(ToothGrowth, aes(x= as.factor(dose), y=len, fill=supp)) +
geom_boxplot() +
scale_x_discrete(name = "Dosage", labels = function(x) {paste0(x, "mg")}) +
scale_y_continuous(name = "Tooth Length") +
scale_fill_discrete(name = "Supplement",
labels = c("Orange Juice", "Ascorbic Acid"))