gpt4 book ai didi

R生成带有空格的标签

转载 作者:行者123 更新时间:2023-12-04 14:36:53 24 4
gpt4 key购买 nike

我尝试使用上标生成标签,因此使用 解析 .我似乎不能使用空格,这是有效的:

GTVol <- 1:10
measuredVol <- 1:10
dat <- data.frame(GTVol, measuredVol)
ggplot(dat, aes(GTVol, measuredVol)) +
geom_point() +
geom_abline(slope=1) +
xlab(parse(text='HarvestedVolume(m^3)')) +
ylab("QSM Volume (m^3)")
但这不起作用:
GTVol <- 1:10
measuredVol <- 1:10
dat <- data.frame(GTVol, measuredVol)
ggplot(dat, aes(GTVol, measuredVol)) +
geom_point() +
geom_abline(slope=1) +
xlab(parse(text='Harvested Volume (m^3)')) +
ylab("QSM Volume (m^3)")
给我以下错误:
Error in parse(text = "Harvested Volume (m^3)") : 
<text>:1:11: unexpected symbol
1: Harvested Volume

最佳答案

通过添加 ~ 更改空格字符

library(ggplot2)
ggplot(dat, aes(GTVol, measuredVol)) +
geom_point() +
geom_abline(slope=1) +
xlab(parse(text='Harvested~Volume~(m^3)')) +
ylab("QSM Volume (m^3)")
-输出
enter image description here

或使用 gsub用于动态替换
  ...
xlab(parse(text=gsub("\\s+", "~", 'Harvested Volume (m^3)'))) +
...

关于R生成带有空格的标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68415086/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com