plotmath

Use dataframe variable names in plot titles

旧街凉风 提交于 2019-12-29 09:28:27
问题 I have a dataframe with several variables that I wish to label and then use in several ggplots. I have applied labels using the labeller package with the following code. library(tidyverse) library(labeller) library(ggpubr) example.df <- data.frame( origin = sample(c("hum_1", "mou_1"), 100, replace = TRUE), v1 = rnorm(100, 100, 5), v2 = rnorm(100, 10,5), v3 = rnorm (100, 25, 5)) example.df <- example.df %>% set_variable_labels(origin = "original sample", v1 = "effect of Rx", v2 = "response",

How do I include italic text in geom_text_repel or geom_text labels for ggplot?

醉酒当歌 提交于 2019-12-29 06:56:08
问题 Is it possible to pass partially italicized text labels into ggplot? I have tried using the expression and italic commands ( expression(paste(italic("some text"))) ), but these cannot be passed into a data frame because the result of the commands is not atomic. Setting the parameter fontface = "italic" also doesn't suffice, since this italicizes the entire label, rather than just a select set of characters in the label. For instance, I would like some necessarily italicized Latin phrases to

Use a variable within a plotmath expression

瘦欲@ 提交于 2019-12-28 02:01:27
问题 I'm trying to place the results of a regression (i.e., R2) in a graph, but can't seem to figure out how to call a variable from within an expression (it pastes the variable name). Here is my code. R2Val <- signif(summary(sMod_pre90)$r.squared[1], 2) text(92, 4, expression(paste(R^2, " = ", R2Val)), adj = 0, cex = 0.85) 回答1: Use bquote() . Here is an example with dummy data: set.seed(1) DF <- data.frame(A = rnorm(100), B = rnorm(100)) mod <- lm(B ~ A, data = DF) R2Val<-signif(summary(mod)$r

Italicizing the main word but not the subscripted word

耗尽温柔 提交于 2019-12-24 02:45:31
问题 I was wondering how to only make the main word d in my text() to appear in italic, but the subscripted word "unbiased" to remain as ordinary text? Please see my R code below the following picture. Here is my R code: plot(1:10, ty="n") text( 4, 4.5, bquote(italic(d[(unbiased)])), cex = 5) 回答1: Keep the "unbiased" outside italic or use plain : plot(1:10, ty = "n") # original text(5, 4, bquote(italic(d[(unbiased)])), cex = 5) # use plain text(5, 6, bquote(italic(d[(plain(unbiased))])), cex = 5)

How do I write a plot containing a symbol to PDF in R?

南楼画角 提交于 2019-12-23 10:26:24
问题 I want to use the infinity sign on the x-axis of a box plot in R, which I want to write to a PDF file. I can set the infinity symbol by doing names(data)[9] <- "∞" but that gets me encoding errors when trying to write: conversion failure on '∞' in 'mbcsToSbcs': dot substituted for <...> 回答1: You can either use Unicode as in this example: using Unicode 'dingbat-like' glyphs in R graphics, across devices & platforms, especially PDF (infinity is Unicode 8734): in particular, it's possible that

leading superscript in plotmath expression (w/ggplot2)

那年仲夏 提交于 2019-12-23 09:09:30
问题 I'd like to use plotmath to create an axis containing a leading superscript in a ggplot2 plot. Creating superscripts on axis labels works nicely, like so: require(ggplot2) ggplot(mtcars, aes(x=disp, y=mpg)) + geom_point() + ylab(expression(x[y])) However, I'd like to have my axis label read "y(superscript)x" - logically that would be ^yx , but that won't parse: Error: unexpected '^' in: " geom_point() + ylab(expression(^" Is there a way to force a superscript at the beginning of a statement?

Add a bold female symbol to ggplot2 using annotate

痞子三分冷 提交于 2019-12-19 18:29:51
问题 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,

Using italic() with a variable in ggplot2 title expression

狂风中的少年 提交于 2019-12-17 20:47:47
问题 When I make a map using ggplot2 and attempt to italicize part of the figure title using a combination of expression() and italic() using a string, my map comes out as desired: plottitle <- expression(paste('Example map with ', italic('italics'))) crimes <- data.frame(state = tolower(rownames(USArrests)), USArrests) states_map <- map_data("state") map <- ggplot(crimes, aes(map_id = state)) + geom_map(aes(fill = Murder), map = states_map) + expand_limits(x = states_map$long, y = states_map$lat)

R ggplot annotated with atop using three values and bgroup

允我心安 提交于 2019-12-13 13:17:02
问题 Is there any way to annotate a ggplot with three lines one on top of the other, while keeping the text sizes the same across the three lines? I am almost there but the text sizes are different in the third line, it looks like the bgroup is only using the first two lines and I cannot get this right... I am adding the text using to "atop" applications from "?plotmath", which works fine but the text in the third line comes out in a different size compared to the other two lines... library

Minus as an exponent in plotmath (in ggplot2 legend)

落爺英雄遲暮 提交于 2019-12-12 12:38:57
问题 I'm trying to make a legend in a ggplot2 plot that contains a minus sign as an exponent (with no other characters in the exponent). However, I can't figure out the plotmath syntax. It seems like the following would work: expr1 <- expression(paste("text", main[sub]^{-})) ggplot(mpg, aes(x=cty, y=hwy, colour=drv)) + geom_point() + scale_colour_discrete(labels=c(expr1, "b", "c")) (And it does work if we say expr1 <- expression(paste("text", main[sub]^{super})) . Is there an escape character or