plotmath

Transform numbers with exponents to plotmath commands for beautiful legends in R

烈酒焚心 提交于 2019-12-06 09:13:56
I'm trying to generate a beautiful legend in R plots. I have a factor=1e-5 , that should appear nicely formatted in the legend. I found a nice function in the package sfsmisc , that transforms numbers to expressions. To add this expression to my bquote command, it seems that I need to transform itto a call. unfortunately, there are braces added at the end of the string ( 10^-5() ). Is there a way to avoid the addition of thoses braces? Or is there even an easier way to transform numbers to plotmaths commands for their use in legends? (without doing it manually) factor = 1e-5 alpha = 1:10 omega

How to use bquote in combination with ggplot2 geom_label?

你。 提交于 2019-12-05 17:43:52
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 coerce class ‘"formula"’ to a data.frame What am I doing wrong? ggplot doesn't like to work with

Subscripts in R when adding other text

谁说胖子不能爱 提交于 2019-12-05 02:00:42
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. 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 separator) are used to separate items and that no quotes are needed unless you are using a plotmath

Using subscript and line break at the same time in plot titles in R

梦想的初衷 提交于 2019-12-04 21:51:40
I wish to include a subscript and a title running into two lines at the same time but am not getting desired result with following commands: base<-'B1' compare<-'A1' plot (1, 1, main = bquote('Annual mean' ~CO[2] ~'Flux Difference: \n' ~.(compare)~ 'minus'~.(base))) I wish to insert a line break after 'Flux Difference' but its not happening instead this term is hanging nowhere. Please help me. Thanks, Munish This is a fairly common request and there is no really clean answer. Plotmath will not accept a "\n" (and the help page documents this.) One dodge is to use each line as an argument to the

Chemical formula (or mathematical expression) in GNU R plot title

泪湿孤枕 提交于 2019-12-04 16:52:59
How can i write H2o in the title of a plot? H2 works: plot(main=expression("H"[2]),0) H2O fails: plot(main=expression("H"[2]"O"),0) This solution will work only, if i have a space in front " " plot(main=expression(" "*H[2]*"O"),0) You were close. This works: plot(1:10, main = expression(H[2]*O)) The reason for this is that the 2 is a subscript to element H and you want to position element O next to the H . The notation x * y in an expression means juxtapose x with y , i.e. place x and y together. See ?plotmath for more. 来源: https://stackoverflow.com/questions/13147591/chemical-formula-or

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

 ̄綄美尐妖づ 提交于 2019-12-03 11:35:19
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] == .(revenue)) But it produces errors. Use {} to put an invisible grouping around the first equality. text

Bolding Greek letters in R

∥☆過路亽.° 提交于 2019-12-02 04:28:55
问题 I want to add a greek letter to my the margin of a figure, and I used the line of code below: mtext(side=2,line=6,text=expression(paste(beta,"-Actin Normalized")),font=2,cex=2) However, when I use the mtext function in combination with greek letters it no longer bolds the line of text. Is there any good way to add margin text with greek letters and retain bold font? Thanks. 回答1: You can use the bold plotmath function: expression(bold(paste(beta,"-Actin Normalized"))) And before you ask for

Add a bold female symbol to ggplot2 using annotate

爱⌒轻易说出口 提交于 2019-12-01 17:23:29
I'm trying to use the female symbol, ♀ in my plot. It's pretty faint (well, it looks faint on my actual graph), so I was hoping to make it bold face. df <- data.frame(x = c(0, 1), y = c(0, 1)) ggplot(df, aes(x, y)) + geom_point() + theme_bw() + annotate("text", x = 0.5, y = 0.7, label = "2016 ♀", size = 7, hjust = 0, colour = "grey50") I've tried the following, but none seem to work: ggplot(df, aes(x, y)) + geom_point() + annotate("text", x = 0.5, y = 0.7, label = "2016~bold(♀)", size = 7, hjust = 0, parse = TRUE) # error message: Error in parse(text = as.character(lab)) : <text>:1:11:

How to underline text in a plot title or label? (ggplot2)

家住魔仙堡 提交于 2019-12-01 15:42:00
Please pardon my ignorance if this is a simple question, but I can't seem to figure out how to underline any part of a plot title. I'm using ggplot2 . The best I could find was annotate("segment") done by hand , and I have created a toy plot to illustrate its method. df <- data.frame(x = 1:10, y = 1:10) rngx <- 0.5 * range(df$x)[2] # store mid-point of plot based on x-axis value rngy <- 0.5 * range(df$y)[2] # stores mid-point of y-axis for use in ggplot ggplot(df, aes(x = x, y = y)) + geom_point() + ggtitle("Oh how I wish for ..." ) + ggplot2::annotate("text", x = rngx, y = max(df$y) + 1,

How to underline text in a plot title or label? (ggplot2)

半腔热情 提交于 2019-12-01 14:36:04
问题 Please pardon my ignorance if this is a simple question, but I can't seem to figure out how to underline any part of a plot title. I'm using ggplot2 . The best I could find was annotate("segment") done by hand, and I have created a toy plot to illustrate its method. df <- data.frame(x = 1:10, y = 1:10) rngx <- 0.5 * range(df$x)[2] # store mid-point of plot based on x-axis value rngy <- 0.5 * range(df$y)[2] # stores mid-point of y-axis for use in ggplot ggplot(df, aes(x = x, y = y)) + geom