2017-06-08 24 views
0

私は、凡例にギリシャ語の文字と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 

Graph with ggplot

plotly使用した場合、ギリシャ文字とx軸のための大胆な伝説が消えしかし:

p=plotly_build(p) 
style(p, hoverinfo = "x+y") %>% 
layout(legend = list(x = 0.1, y = 0.9, font=list(size=12))) 

Same graph using plotly

答えて

0

あなたはでしょうggplotグラフにかなり近づくには2つの小さな変更が必要です。

は(UbuntuのでRStudioで動作します)ggplotにパイのためのHTMLコードを使用します(WindowsでRStudioで動作します)またはπを追加

layout(legend = list(x = 0.1, 
        y = 0.9, 
        font=list(size=12)), 
     xaxis = list(title = "<b>dose</b>") 
) 

手動で大胆にxaxistitleを設定します。

colour = paste("&pi; = ",5,sep="") 

または

colour = paste("π = ",5,sep="") 

enter image description here

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 
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 
+0

おかげ@Maximilian!残念ながら、piのHTMLコードは私にとってはうまくいかないようです。私はちょうど "π = 5"と伝説を得る。これについて何かお勧めしますか? ありがとう! ここに私のsessionInfo:Rバージョン3.3.3(2017-03-06) プラットフォーム:x86_64-apple-darwin13.4.0(64ビット) 実行中:OS X Yosemite 10.10.5 – Nicolas

+0

@ニコラス:奇妙な!私はUbuntuでRStudioを試してみたところ、同じ問題が発生しました。私は質問を更新します。 –

+0

あなたの代替ソリューションは、私のMacでも動作します、ありがとう! – Nicolas

関連する問題