r - 字符向量上的下标和上标
问题描述
我希望我的字符向量上同时有下标和上标,相对于绘图上的 X 和 Y 值。
例如,X 值是上标,Y 值是下标。
我已经尝试粘贴上标然后绘制这些,虽然它没有像预期的那样工作
情节代码:
ggplot(test, aes(x=Neutron, y = Protons, group = Isotopes)) + geom_point() +geom_line() +geom_label(label = test$Isotopes) + scale_x_continuous(breaks = test$Neutron) + scale_y_continuous(breaks = test$Protons)
> ggplot(test, aes(x=Neutron, y = Protons)) + geom_point() +geom_line() +geom_label(label = test$Isotopes) + scale_x_continuous(breaks = test$Neutron) + scale_y_continuous(breaks = test$Protons)
可重现的代码:
structure(list(Neutron = c(237, 233, 233, 229, 225, 225, 221,
217, 213, 213, 209, 209, 205), Protons = c(93, 91, 92, 90, 88,
89, 87, 85, 83, 84, 82, 83, 81), Isotopes = c("Np", "Pa", "U",
"Th", "Ra", "Ac", "Fr", "At", "Bi", "Po", "Pb", "Bi", "Tl")), class = "data.frame", row.names = c(NA,
-13L))
解决方案
我们可以使用sprintf
orpaste
创建标签,然后指定label
inaes
和parse
it ingeom_label
library(ggplot2)
lbl1 <- with(test, sprintf('%s[%d]^%d', Isotopes, Protons, Neutron))
ggplot(test, aes(x=Neutron, y = Protons, label = lbl1)) +
geom_point() +
geom_line() +
geom_label(parse= TRUE) +
scale_x_continuous(breaks = test$Neutron) +
scale_y_continuous(breaks = test$Protons)
-输出
推荐阅读
- arrays - 无法获取数组令牌大小
- endpoint - 如何使用 Coinbase API 判断市场是上涨还是下跌一定百分比?
- jquery - 如何通过自动单击闪亮的链接自动重定向到闪亮的选项卡而不会被chrome阻止?
- angular - Angular,在控制台中防止“未定义不是评估对象...”
- python - 在 Python 中使用 Azure-key-vault 中的密钥加密 azure blob
- axlsx - caxlsx / axlsx 数据透视表在单独的工作表上
- python - Django - 过滤具有大于限制值的字段的对象
- dart - Dart 可选参数为空类型
- ruby - Ruby 2.7 和 3.0 分叉内存消耗
- clonezilla - OCS_Prerun 参数在新 SSD 设置上失败