r - ggplot2 标签中的下标

标签 r ggplot2

以下命令

library(ggplot2)
ggplot(PlantGrowth, aes(x=group, y=weight)) + geom_boxplot()

制作这张图。

this graph .我想知道如何将xlabels 获取为ctrl、trt_1 和trt_2,这里1 和2 在下标中。因为我需要 png 格式的图表,所以我避免使用 tikzDevice 和 pgfSweave。预先感谢您的帮助。

最佳答案

这是一个例子:

ggplot(PlantGrowth, aes(x=group, y=weight)) + geom_boxplot() + 
  scale_x_discrete(breaks = unique(PlantGrowth$group), labels = c(expression(ctrl), expression(trt[1]), expression(trt[2])))

enter image description here

关于r - ggplot2 标签中的下标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8514478/

相关文章:

r - 如何更改 ggplot 中小平面上 strip 的大小?

R ggsave 保存缩略图大小(200 x 200),缩放图像

r - 这里 + ggplot2 特别是 ggsave

R:每次在数据中出现 n 个唯一级别时对因素进行分组

r - read.dcf(path_desc) : Line starting 'This corresponds to ...' is malformed 中的 devtools 错误

r - R Markdown ioslides 中的目录

r - ggplot 在 for 循环中从数据框中提取行,显示不同的颜色

在 gganimate 中将动画 barplot 条上的标签舍入?

r - 与 S3 存储桶的 Sparklyr 连接抛出错误

R - 仅按时间子集数据帧