R 具有多个文本和颜色的标题

R 具有多个文本和颜色的标题,r,ggplot2,R,Ggplot2,我正在ggplot中为我的绘图添加标题,没有问题。我可以改变位置,单色和文字 我想做的是添加一个标题,有多个文本,每个文本(单词)是一个单独的颜色 library(ggplot2) ggplot(xdata, aes(x = Days, y= maxGenOutletTemp)) + geom_point(shape = 18, color = "#8181F7")+ geom_hline(yintercept = `1yrWTGbase`$Gen.Cool.1YRBase, linetyp

我正在ggplot中为我的绘图添加标题,没有问题。我可以改变位置,单色和文字

我想做的是添加一个标题,有多个文本,每个文本(单词)是一个单独的颜色

library(ggplot2)

ggplot(xdata, aes(x = Days, y= maxGenOutletTemp)) + 
geom_point(shape = 18, color = "#8181F7")+
geom_hline(yintercept = `1yrWTGbase`$Gen.Cool.1YRBase, linetype="solid", color = "#04B431", size = 1)+
geom_smooth(method = lm, linetype = "dashed", color = "red", fullrange = TRUE)+
geom_smooth(method = "auto",se = F)+

scale_x_datetime(date_breaks = "1 week", date_minor_breaks = "1 day",
           date_labels = "%m/%d")+ 
scale_y_continuous(limits=c(min(xdata$maxGenOutletTemp), 85))+

theme_light()+

labs(title = "WTG Generator Coolant.Outlet last 90 days  vs  1yr Wtg.Baseline",
   subtitle = "Last 90 Days",
   caption = "Green.Line -> 1yr WTG.baseline  //  Red.Line -> Trend line  //  Blue.Line -> Daily Moving Trend")+

theme(
plot.title = element_text(hjust = 0.5, size = 14),    # Center title position and size
plot.subtitle = element_text(hjust = 0.5),            # Center subtitle
plot.caption = element_text(hjust = 0, face = "bold"), # move caption to the left
)
我想要一个这样的标题:

1年风电机组基线(绿色文本)、趋势线(红色文本)、每日移动趋势(蓝色文本)


使用
ggtext
包是可能的(我认为目前只在Github上提供)。它允许使用HTML作为标题

library(ggplot2)
library(ggtext)

mycaption <- '<span style="color:red;">RED</span> // <span style="color:blue;">BLUE</span>'

ggplot(iris) + 
  aes(Sepal.Length, Sepal.Width) + 
  labs(caption = mycaption) + 
  theme(plot.caption = element_markdown(hjust = 0, size = 18))
库(ggplot2)
图书馆(ggtext)

我的标题你能在这里用HTML在标题中也包括一个图像吗?@MokeEire我不知道。Try:)我的基本尝试是将
'
添加到
mycaption
中,但
网格中出现错误。调用
-
视口的维度为零
?我的HTML知识不是很好,所以稍微学习一下可能会有所帮助me@MokeEire缺少
image.png
周围的引号。这是有效的:
mycaption