plotmath

preventing centering multilayered caption in ggplot2

大兔子大兔子 提交于 2019-12-12 11:31:07
问题 This is part-2 to my previous question (getting constant text size while using atop function in r). Now the issue relates to how I can prevent plotmath from centering the text to avoid the extra spacing (highlighted here in yellow). I want everything aligned to the right side of the plot. (Unfortunately, I can't replace substitute with expression if that's what your suggestion is going to be.) Any suggestions? library(ggplot2) ggplot(iris, aes(Species, Sepal.Length)) + geom_boxplot() + labs

Error when exporting ggplot graphs to pdf: invalid font type

余生颓废 提交于 2019-12-11 02:24:46
问题 I'm having trouble getting my plots to save using ggsave(). I keep getting this error: Error in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, : invalid font type I don't understand why I would be getting this error.. I'm not using any special type of font. I looked at these similar questions: Export to pdf not displaying properly in ggplot2 Saving ggplot graph to PDF with fonts embedded in r But they haven't worked for me. The code works fine and the plots print perfectly in

getting constant text size while using atop function in r

蓝咒 提交于 2019-12-10 16:46:51
问题 Below is a much simpler example of a complicated custom function I have written. In the full-length form of this function, "layer1" corresponds to caption entered by the user, "layer2" corresponds to results from a statistical test, and "layer3" corresponds to details about the statistical test carried out. But when all three layers are included in the caption, it looks something like this- library(ggplot2) ggplot(iris, aes(Species, Sepal.Length)) + geom_boxplot() + labs(caption = substitute

Subscripts in R when adding other text

情到浓时终转凉″ 提交于 2019-12-10 02:06:17
问题 How would you add a subscript to one particular word of a title in R? For example, suppose the title is "A_2 and B_2." How would you add these two subscripts? I know that expression("A"[2]) and expression("B"[2]) individually add subscripts to these letters. 回答1: You do not need paste (or quotes for that matter) at all: expression( A[2]~and~B[2] ) Test: plot(1,1, main=expression( A[2]~and~B[2] ) ) The syntactic principle is that tildes (which creates a space) and asterisks (non-space plotmath

Use sub-/superscript and special characters in legend texts of R plots

谁说胖子不能爱 提交于 2019-12-09 10:43:57
问题 I generate a plot for multiple datasets. Each of the datasets should get it's own legend, which might contain greek letters, plotmath symbols or sub and superscrition. I'd like to generate the legend-texts in a loop. Bquote works fine, if there is only one legend text. If I try to add additinal legend texts, the plotmath-commads get lost,... x <- 0:10 y1 = x * x y2 = x * 10 plot (1,1, type="n", xlab=bquote(Omega), ylab="Y", las=1, xlim=range(x), ylim=range(y1, y2)) lines(x, y1, col=1, pch=1,

How to use several equal signs in text(x,y,expression(…))

若如初见. 提交于 2019-12-09 09:06:53
问题 is there a solution to use more than one equals signs in a expression (which are not within brackets)? I'm currently doing it with " = ". But thats not so nice, since == and " = " look different on the plot. Minimal sample: plot(0:5,0:5, type="n") saleprice <- 35 revenue <- 98000 text(1, 2, bquote(paste(R(x[G]) == .(saleprice)%.%x[G], " = ", .(revenue)))) See the following image for the current status: sample image I would like to use something like: bquote(R(x[G]) == .(saleprice)%.%x[G] == .

plot() and do.call(): How to pass expressions to plot title when '…' is used otherwise?

岁酱吖の 提交于 2019-12-08 01:32:13
问题 When run the following code, I obtain Error in as.graphicsAnnot(text) : could not find function "bold" . How can I fix this? my.qq <- function(x, main=expression(bold(italic(F)~~"Q-Q plot")), margs=list(side=3, cex=par("cex.main"), font=par("font.main"), adj=par("adj"), xpd=NA), ...) { plot(qnorm(ppoints(n <- length(x))), sort(x), ...) do.call(mtext, c(list(main), margs)) } x <- rnorm(100) my.qq(x) my.qq(x, main=substitute(bold(italic(F)[N(mu.,s2.)]~~"Q-Q plot"), list(mu.=0, s2.=1))) # fails

r label plots with fractions

时间秒杀一切 提交于 2019-12-07 21:40:14
问题 I would like to create 3 plots each containing a plot of 2 lines from different data frames, and then label each plot with a specific fraction. So for example I have the 3 data frames: df1 <- data.frame(x=c(1,2,3,4),y=c(2,3,4,5), z=c(3,3,6,8)) df2 <- data.frame(x=c(3,4,5,6),y=c(1,3,6,7), z=c(2,4,4,8)) df3 <- data.frame(x=c(1,2,2,3),y=c(2,5,6,9), z=c(2,5,6,7)) And I would like to: 1) Create 3 different plots for each data frame, each with one red and one blue line; 2) Add an annotation over

How to use bquote in combination with ggplot2 geom_label?

时光总嘲笑我的痴心妄想 提交于 2019-12-07 10:26:38
问题 I've read the following article: https://trinkerrstuff.wordpress.com/2018/03/15/2246/ Now I'm trying to use the suggested approach with bquote in my plot. However I can't get it to work. I have the following code x <- seq(0, 2*pi, 0.01) y <- sin(x) y_median <- median(y) ggplot(mapping = aes(x = x, y = y)) + geom_line() + geom_label(aes(label = bquote("median" ~ y==~.y_median), x = 1, y = y_median)) I get the following error: Error in as.data.frame.default(x[[i]], optional = TRUE) : cannot

r label plots with fractions

℡╲_俬逩灬. 提交于 2019-12-06 11:00:24
I would like to create 3 plots each containing a plot of 2 lines from different data frames, and then label each plot with a specific fraction. So for example I have the 3 data frames: df1 <- data.frame(x=c(1,2,3,4),y=c(2,3,4,5), z=c(3,3,6,8)) df2 <- data.frame(x=c(3,4,5,6),y=c(1,3,6,7), z=c(2,4,4,8)) df3 <- data.frame(x=c(1,2,2,3),y=c(2,5,6,9), z=c(2,5,6,7)) And I would like to: 1) Create 3 different plots for each data frame, each with one red and one blue line; 2) Add an annotation over the blue line of each plot using a different fraction for each plot. For example the plot for data frame