没有开罗的ggplot unicode字符? [英] ggplot unicode characters without Cairo?

查看:113
本文介绍了没有开罗的ggplot unicode字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望Unicode字符出现在我的情节中,作为混合字符串的一部分,例如ρ= 0.84 其中0.84保存在变量中,比方说 cor.value $ b

这实际上排除了诸如表达式 bquote (建议



部分点被切断,没有被剪裁。因此,当它与边框叠加时,边框稍微偏移,点透过边框(这里您只能在底部看到它,而在其他地方看得更清楚)。底部和右侧边框比左侧和顶部边框厚。在开罗,点背后非常苍白的灰色带更宽。这些问题在标准PDF设备中不存在。





我目前正在开发Fedora 21系统,但是这个文件也必须在Windows 8或10上编译,最好也在其他Linux版本上编译。




这是绘图的代码(打算以小尺寸观看,大约2 x 1.5英寸)。当前的计划是将文本放置在 ca 变量中,并将其放置在轴标签的位置,但我想保留我的选项以便稍后将其添加为注释:

  offset.plotdata < -  data.frame(idealability = c(2.95,0.85,0.75,1.15,2.25,2.05, (A,B,C,D,E,F,A,D,小写字母, ,E,C,F,B),调查问卷= c(rep(pre,6),rep(post,6)))
offset.plotdata $装饰(1,2,3,4,5,NA,1,2,3,4,5,NA)
middle.blue< - #2186D9
变量.name< - 可理解性
cor.value <-0.84
ca < - rho = 0.84
ggplot(offset.plotdata,
aes_string(x = (c(5,0.5))调查问卷,y =变量名,
group =lowercase.pseudonym))+
geom_line(color = middle.blue)+
+
theme_bw()+
主题(panel.grid.major.y = element_line(size = 5,color =#f8f8f8),
panel.grid.minor。 y = element_blank(),
panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank(),
text = element_text(size = 9) ,
axis.text = element_text(size = 8),
axis.ticks.y = element_blank(),
plot.margin = unit(c(0,5,0,0) ,mm)
#axis.title.y = element_text(margin = margin(0,20,0,0))
)+
labs(y =Angekreuzte Option, x = as.character(ca))+
scale_x_discrete(expand = c(0,0),label = c(Vorher,Nachher))+
#ggtitle(gepaarte Antworten )+
geom_point(data = offset.plotdata,
aes(x =问卷,y = decorative.points),
fill = middle.blue,
color = middle.blue ,
size = 5)


解决方案

不知道为什么表达式(...)不起作用(即它会打印希腊字母,但它仍然会打印表达式),并且用波形符()指定表达式的快捷方式确实有效,但这适用于我:

  g0 < -  [...图的其余部分...] 

cor.value < - 0.84
ca < - 替代(〜rho == x,list(x = cor.value))
g0 + labs(y =Angekreuzte Option,x = ca )


I would like to have Unicode characters appear in my plot, as a part of a mixed string, for example ρ=0.84 where the 0.84 is saved in a variable, let's say cor.value.

This practically excludes solutions such as expression or bquote (suggested here). I don't know if they would work alone, but trying to combine them with a variable's value via paste is a problem. The only way I could got it to work was by actually using the unicode symbol in my source. It even showed up on the plot in R Studio.

But when I tried to print, I only got .. instead. The only suggestion I have found so far is to use Cairo, but Cairo is mangling the remainder of my plot, so I want to stick with the original pdf device.

Is there any chance, by using Unicode or something else, to get that string printed within the plot, but not having to use Cairo?


Here is an example of what Cairo does (this is supposed to be a corner of the graph, with a grey border):

The partial dot is cut off, not clipped. So when it is overlayed with the border, the border is slightly offset, and the dots "show through" the border (here you only see it on the bottom, elsewhere it is more visible). And the bottom and right border are thicker than the left and top border. The very pale grey band behind the dot is broader in Cairo. These problems are not present in the standard PDF device.

I am currently working on a Fedora 21 system, but this document has to also compile on Windows 8 or 10, and preferably also on other Linux flavors.


Here is the code for the plot (intended to be viewed at smallish sizes, around 2x1.5 inch). The current plan is to have the text in the c.a variable and place it where an axis label would be, but I want to keep my options open to make it an annotation later:

 offset.plotdata <- data.frame(understandability=c(2.95, 0.85, 0.75, 1.15, 2.25, 2.05, 1.95, 2.15, 2.25, 0.75, 2.05, 0.85), lowercase.pseudonym=c("A", "B", "C", "D", "E", "F", "A", "D", "E", "C", "F", "B"), questionnaire=c(rep("pre", 6), rep("post", 6)))
offset.plotdata$decorative.points <- c(1,2,3,4,5,NA,1,2,3,4,5,NA)
middle.blue <- "#2186D9"
variable.name <- "understandability"
cor.value <- 0.84
c.a <- "rho = 0.84"
ggplot(offset.plotdata, 
       aes_string(x="questionnaire", y=variable.name, 
                  group="lowercase.pseudonym"))+
  geom_line(colour=middle.blue)+
  ylim(c(5,0.5))+
  theme_bw()+
  theme(panel.grid.major.y = element_line( size=5, color="#f8f8f8"),
        panel.grid.minor.y=element_blank(),
        panel.grid.major.x=element_blank(),
        panel.grid.minor.x=element_blank(),
        text = element_text(size=9), 
        axis.text=element_text(size=8),
        axis.ticks.y=element_blank(),
        plot.margin = unit(c(0,5,0,0), "mm")
        #axis.title.y=element_text(margin=margin(0,20,0,0))
  )+
  labs(y="Angekreuzte Option", x=as.character(c.a))+
  scale_x_discrete(expand = c(0,0), label=c("Vorher", "Nachher"))+
  #ggtitle("gepaarte Antworten")+
  geom_point(data=offset.plotdata, 
             aes(x=questionnaire,y=decorative.points), 
             fill=middle.blue, 
             colour=middle.blue, 
             size=5)

解决方案

I don't know why expression(...) doesn't work (i.e. it does print the Greek letters but it still prints "expression" as well) and the shortcut of specifying an expression with a tilde (~) does work, but this works for me:

g0 <- [... the rest of the graph ...]

cor.value <- 0.84
c.a <- substitute(~rho == x, list(x=cor.value))
g0 + labs(y="Angekreuzte Option", x=c.a)

这篇关于没有开罗的ggplot unicode字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆