geom-text

Why is geom_text() plotting the text several times?

99封情书 提交于 2020-05-13 07:35:15
问题 Please consider the following minimal example: library(ggplot2) library(ggrepel) ggplot(mtcars) + aes(x = mpg, y = qsec) + geom_line() + geom_text(x = 20, y = 20, label = "(20,20)") I guess you can see pretty easily that the text "(20,20)" is heavily overplotted (actually, I don't know whether that's the correct word. I mean that the text is plotted several times at one location). If I use annotate() , this does not happen: ggplot(mtcars) + aes(x = mpg, y = qsec) + geom_line() + annotate(

Add text labels at the top of density plots to label the different groups

ぃ、小莉子 提交于 2020-05-09 05:41:51
问题 I have the following ggplot density plot ggplot(mpg, aes(cty)) + geom_density(aes(fill=factor(cyl))) How do I remove the legend , and add labels above each distribution to denoted the group it belongs to? 回答1: Like it is said in the comment by @DavidKlotz, the maxima of the densities of cty per groups of cyl must be computed beforehand. I will do this with Hadley Wickham's split/lapply/combine strategy. sp <- split(mpg$cty, mpg$cyl) a <- lapply(seq_along(sp), function(i){ d <- density(sp[[i]]

Annotating text on individual facet in ggplot2 using geom_text

杀马特。学长 韩版系。学妹 提交于 2020-01-14 13:57:34
问题 With the following code, I obtain text on each facet but the text is superimposed : "X1" and "X2" are superimposed on each facet. Where is the problem in my code ? R code : new_df <- data.frame(f = as.factor(rep(1:2, 15)), x = rnorm(30), y = runif(30)) g <- ggplot(data = new_df, aes(x = x, y = y)) + geom_point() g <- g + facet_grid(. ~ f) g label_graph <- data.frame(label = c("X1", "X2")) g <- g + geom_text(data = label_graph, mapping = aes(x = Inf, y = -Inf, label = label), hjust = 1.1,

How to add a complex label with italics and a variable to ggplot?

拟墨画扇 提交于 2020-01-11 03:08:27
问题 I have read many postings on this topic using expression() , paste() , and bquote() , or some combination. I think I am close to solving my problem, but I just can't get there. The following script generates a plot labelled with "y = 1 + 2(x); r^2= 0.9". How can I italicize "y" and "x", and italicize the "r" and superscript the 2 of "r^2"? If I have overlooked a relevant earlier post, sorry, but please direct me to it. df <- data.frame(x=c(1:5), y=c(1:5)) a <- 1 b <- 2 r2 <- 0.9 eq <- paste(

How to add a complex label with italics and a variable to ggplot?

大城市里の小女人 提交于 2020-01-11 03:08:05
问题 I have read many postings on this topic using expression() , paste() , and bquote() , or some combination. I think I am close to solving my problem, but I just can't get there. The following script generates a plot labelled with "y = 1 + 2(x); r^2= 0.9". How can I italicize "y" and "x", and italicize the "r" and superscript the 2 of "r^2"? If I have overlooked a relevant earlier post, sorry, but please direct me to it. df <- data.frame(x=c(1:5), y=c(1:5)) a <- 1 b <- 2 r2 <- 0.9 eq <- paste(

Unicode characters in ggplot labels

纵饮孤独 提交于 2020-01-05 04:26:09
问题 I can get ggplot to print Japanese Unicode characters in axis labels and legends, but not in labels. Is this a bug? library(extrafont) library(ggplot2) data_frame <- cbind.data.frame("number"=c(1:3), "kana"=c("い","ろ","は")) ggplot(data=data_frame, aes(kana, number)) + geom_point() + theme_gray(base_family = "Meiryo") ##works great ggplot(data=data_frame, aes(kana, number, label=kana)) + geom_point() + geom_label() + theme_gray(base_family = "Meiryo") ##no such luck 来源: https://stackoverflow

How to write after decimal zero in ggplot (geom_text)

独自空忆成欢 提交于 2020-01-03 05:21:10
问题 I am wondering how i can put after decimal zero in the faceted ggplot plot. Following picture make it more clear. I would like to write r-squared =0.61 and 0.30 in two facets of ggplot using geom_text . It writes 0.61 properly but writes only 0.3 and not 0.30 in second plot. see the figure. My working data and codes are below. dput(ssdata) structure(list(Value = c(0.0776799352545487, 0.0249900650410425, 0.0530261633888124, 0.0567436050950435, 0.0120449632406235, 0.0148445528174501, 0

Error: Aesthetics must be either length 1 or the same as the data (4)

不羁岁月 提交于 2019-12-23 23:49:11
问题 I am working with ggmap . the goal is to plot coordinate points on the map and label the points with their names. I have data frame with name, longitude and latitude. The data looks like: df <- structure(list(Station.Area = c("Balbriggan", "Blanchardstown", "Dolphins Barn", "Donnybrook", "Dun Laoghaire", "Finglas"), Latitude = c(53.608319, 53.386813, 53.333532, 53.319259, 53.294396, 53.390325), Longitude = c(-6.18208, -6.377197, -6.29146, -6.232017, -6.133867, -6.298401)), .Names =c("Station

Add less than symbol, “<”, to a ggplot via geom_text in R

无人久伴 提交于 2019-12-21 02:54:23
问题 The short version : How would I make this contrived code plot a proper greek beta character AND the rest of the label string, with the space and the less than character and the numbers formatted as typed? library("ggplot2") df<-data.frame(a=1:15,b=6:20) ggplot(data=df, aes(x=a,y=b)) + geom_point() + geom_text(x=5,y=4,label="beta=1.00 p<0.0001", parse=TRUE) If I leave out the ", parse=TRUE" argument, the string works great, but won't give me a real greek beta. If I leave it in, all hell breaks

ggplot2: geom_text resize with the plot and force/fit text within geom_bar

邮差的信 提交于 2019-12-18 12:24:20
问题 This is actually two questions in one (not sure if goes against SO rules, but anyway). First question is how can I force a geom_text to fit within a geom_bar ? (dynamically according to the values plotted) Looking around, the solutions I found were changing the size of the label. That certainly works, but not for every case. You can change the size for a specific plot to make the text fit within the bar, but when the data changes, you may need to manually change the size of the text again. My