Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 字符向量上的下标和上标_R - Fatal编程技术网

R 字符向量上的下标和上标

R 字符向量上的下标和上标,r,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 = te

我希望在我的字符向量上有下标和上标,相对于绘图上的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
paste
创建标签,然后在
aes
中指定
标签
,并在
geom_标签
中解析它

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)
库(ggplot2)
lbl1