我正在尝试使用图例中的希腊字母和x轴图例中的粗体字符来制作图表。这适用于ggplot:
library(ggplot2)
library(plotly)
## Dataframe
df <- data.frame(dose=c("D0.5", "D1", "D2"),len=c(4.2, 10, 29.5))
## Legend with the greek letter pi
my.labs <- list(bquote(Pi==.(5)) )
## Plot with ggplot
p=ggplot(data=df, aes(x=dose, y=len, group=1,colour = paste("Pi = ",5,sep=""))) +
geom_line()+
geom_point()+
scale_colour_manual(values=3, labels=my.labs)+
theme(legend.title=element_blank(), legend.position = c(.1, .9),axis.title.x = element_text(face="bold", colour="black", size=10))
p
然而,当使用plotly时,希腊字母和x轴的大胆图例消失了:
p=plotly_build(p)
style( p, hoverinfo = "x+y" ) %>%
layout( legend = list(x = 0.1, y = 0.9, font=list(size=12)) )
答案 0 :(得分:0)
您需要进行两项小的更改才能非常接近ggplot
图表。
手动将xaxis
title
设置为粗体
layout(legend = list(x = 0.1,
y = 0.9,
font=list(size=12)),
xaxis = list(title = "<b>dose</b>")
)
在ggplot
中使用pi代码(在Windows中与RStudio一起使用)或添加π
(在Ubuntu中使用RStudio)。
colour = paste("π = ",5,sep="")
或
colour = paste("π = ",5,sep="")
library(ggplot2)
library(plotly)
## Dataframe
df <- data.frame(dose=c("D0.5", "D1", "D2"),len=c(4.2, 10, 29.5))
## Legend with the greek letter pi
my.labs <- list(bquote(Pi==.(5)) )
## Plot with ggplot
p=ggplot(data=df, aes(x=dose, y=len, group=1,colour = paste("π = ",5,sep=""))) +
geom_line()+
geom_point()+
scale_colour_manual(values=3, labels=my.labs)+
theme(legend.title=element_blank(), legend.position = c(.1, .9),axis.title.x = element_text(face="bold", colour="black", size=10))
p
p=plotly_build(p)
p <- style(p, hoverinfo = "x+y" ) %>%
layout(legend = list(x = 0.1,
y = 0.9,
font=list(size=12)),
xaxis = list(title = "<b>dose</b>")
)
p