Ggplot unicode characters without cairo?

I would like Unicode characters to appear in my plot as part of a mixed string, like ρ=0.84 , where 0.84 is stored in a variable, say cor.value .

This virtually eliminates solutions like expression or bquote (suggested here ). I don't know if they will work alone, but trying to combine them with a variable through paste is a problem. The only way to make it work is to use the unicode character in my source. He even appeared on the plot in R Studio.

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

Is it likely using Unicode or something else to get this line printed in the plot, but not to use Cairo?


Here is an example of what Cairo is doing (it should be a corner of the graph with a gray frame):

screenshot from cairo

A partial point is cut off, not cut off. Therefore, when it is superimposed on the border, the border is slightly offset, and the dots “show” the border (here you see it only below, in another place it is more noticeable). Both the lower and right borders are thicker than the left and upper borders. The palest gray strip behind the dot in Cairo is wider. These problems are not found in the standard PDF device.

Screenshot from standard

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


Here is the code for the plot (designed for viewing on small sizes, about 2x1.5 inches). The current plan is to have the text in the ca variable and place it where the axis label would be, but I want my options to open to make this 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 ca <- "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(ca))+ 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) 
+5
source share
1 answer

I don’t know why expression(...) doesn’t work (that is, it prints Greek letters, but it also prints “expression” anyway), and the label for specifying an expression with a tilde ( ~ ) works, but this works for me:

 g0 <- [... the rest of the graph ...] cor.value <- 0.84 ca <- substitute(~rho == x, list(x=cor.value)) g0 + labs(y="Angekreuzte Option", x=ca) 
+2
source

Source: https://habr.com/ru/post/1262824/


All Articles