首页 > 解决方案 > 斜体ggplotly图中的标题

问题描述

我不确定为什么标题没有改变,我可能使用了错误的功能。这是一个例子:

我的数据框moment.curve

moment.curv <- structure(list(row = 1:5, Curvature = c(
  0, 0.001805, 0.004512,
  0.008121, 0.0126
), Moment = c(
  0, 192.0442, 242.8942, 256.6455,
  258.1099
)), class = "data.frame", row.names = c(NA, -5L))

我使用以下代码来创建绘图:

plot.moment.curv <- ggplot(moment.curv) +
 aes(x = Curvature, y = Moment) +
 geom_line(size = 1L, colour = "#0c4c8a") +
 labs(x = "bla", y = "bla") + theme_classic()

我使用以下内容创建一个 ggplotly 交互式绘图,请记住,我想保留这种格式,即在 ggplot 中制作原始绘图,然后使用 ggplotly 将其转换为交互式绘图。我创建的实际数字要复杂得多,这使过程更容易。

ggplotly(
  p = ggplot2::last_plot(),
  width = NULL,
  height = NULL,
  tooltip = "all",
  dynamicTicks = FALSE,
  layerData = 1,
  originalData = TRUE,
) %>% 
 layout(margin = list(b=130,t=100), annotations = 
 list(x = 1, y = -0.4, text = "THE CAPTION", 
      showarrow = F, xref='paper', yref='paper', 
      xanchor='right', yanchor='auto', xshift=0, yshift=0,
      font=list(size=15,fontfacet="italic"))
 )

谢谢!

标签: rggplot2ggplotly

解决方案


要更改字体,您必须使用 HTML 标记,即斜体您的标题使用text = "<i>THE CAPTION</i>".

在此处输入图像描述


推荐阅读