ggrepel

ggplot2 pie plot with geom_text_repel

余生长醉 提交于 2020-01-01 10:48:12
问题 I am plotting multiple pie plots with ggplot2 and succeeded in having the labels plotted in the right positions, as: df <- data.frame(annotation=rep(c("promoter", "intergenic", "intragene", "5prime", "3prime"), 3), value=c(69.5, 16, 10.7, 2.5, 1.3, 57.2, 18.8, 20.2, 2.1, 1.7, 50.2, 32.2, 15.3, 1.2, 1.1), treatment=rep(c("treated1", "treated2", "untreated"), c(5, 5, 5))) library(ggplot2) ggplot(data = df, aes(x = "", y = value, fill = annotation)) + geom_bar(stat = "identity") + geom_text(aes

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

Why does text appear in the legend?

扶醉桌前 提交于 2019-12-25 03:22:56
问题 library(ggplot2) library(ggrepel) set.seed(1234) ss <- sample(1:32, 10) df <- mtcars[ss, ] ggplot(df, aes(wt, mpg))+ geom_point(col = "red") + geom_label_repel(aes(label = rownames(df), fill = factor(cyl)), size = 5, hjust = 1,fontface = 3) In the legend, why does 'a' appear alongside, 4,6,8? 回答1: a symbolizes the text added by geom_label_repel() and it matches the font, colour, etc. of your labels. The picture below shows one of the demo examples of the ggrepel package shown in the package

Justifying lines of text within individual ggrepel labels

余生颓废 提交于 2019-12-23 21:46:51
问题 I have a plot where I'm labelling elements with multi-line ggrepel labels. I'd like to right-justify within some of these and left-justify within others. See example: p <- ggplot() + coord_cartesian(xlim=c(0,1), ylim=c(0,1)) + theme_void() p labelInfo <- data.frame(x=c(0.45,0.55), y=c(0.5,0.5), g=c("I'd like very much to be\nright justified","And I'd like to be\nleft justified")) p + geom_label_repel(data=labelInfo, aes(x,y,label=g), box.padding = 0.5, point.padding = 0.75, nudge_x = c(-0.05

Adding text annotation to a clustering scatter plot (tSNE)

北城余情 提交于 2019-12-21 18:56:10
问题 I have XY data (a 2D tSNE embedding of high dimensional data) which I'd like to scatter plot . The data are assigned to several cluster s, so I'd like to color code the points by cluster and then add a single label for each cluster , that has the same color coding as the cluster s, and is located outside (as much as possible) from the cluster 's points. Any idea how to do this using R in either ggplot2 and ggrepel or plotly ? Here's the example data (the XY coordinates and cluster assignments

using `rlang` for conditional labelling in `ggplot` using `ggrepel`

﹥>﹥吖頭↗ 提交于 2019-12-13 19:10:07
问题 I am writing a custom function to create a scatterplot with labels attached to points. Here is a minimal rendition of the same. # needed libraries library(tidyverse) library(ggplot2) library(ggrepel) # custom function label_adder <- function(data, x, y, label.var) { # basic plot plot <- ggplot(data = data, mapping = aes( x = !!rlang::enquo(x), y = !!rlang::enquo(y) )) + geom_point() + geom_smooth(method = "lm") # adding label plot <- plot + geom_label_repel(mapping = aes(label = !!rlang:

Add directlabels to geom_smooth rather than geom_line

好久不见. 提交于 2019-12-07 13:01:07
问题 I recognize that this question is a close duplicate of this one, but the solution there no longer works (using method="last.qp" ), so I'm asking it again. The basic issue is that I'd like to use directlabels (or equivalent) to label smoothed means for each group (from stat_smooth() ), rather than the actual data. The example below shows as close as I've gotten, but the labels aren't recognizing the grouping, or even the smoothed line. Instead, I'm getting the label at the last point. What I'd

Adding text annotation to a clustering scatter plot (tSNE)

丶灬走出姿态 提交于 2019-12-04 11:22:51
I have XY data (a 2D tSNE embedding of high dimensional data) which I'd like to scatter plot . The data are assigned to several cluster s, so I'd like to color code the points by cluster and then add a single label for each cluster , that has the same color coding as the cluster s, and is located outside (as much as possible) from the cluster 's points. Any idea how to do this using R in either ggplot2 and ggrepel or plotly ? Here's the example data (the XY coordinates and cluster assignments are in df and the labels in label.df ) and the ggplot2 part of it: library(dplyr) library(ggplot2) set

Override horizontal positioning with ggrepel

99封情书 提交于 2019-11-29 14:41:58
I'm working on a chart similar to a slopegraph, where I'd like to put labels along one or both sides with ample blank space to fit them on both sides. In cases where labels are very long, I've wrapped them using stringr::str_wrap to place linebreaks. To keep labels from overlapping, I'm using ggrepel::geom_text_repel with direction = "y" so the x-positions are stable but the y-positions are repelled away from one another. I've also got hjust = "outward" to align the left-side text at its right end and vice versa. However, it seems that the repel positioning places the label's bounding box with

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

試著忘記壹切 提交于 2019-11-29 07:33:26
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 be italicized in a label (such as "in vivo" in "in vivo point"). library(ggplot) library(ggrepel) df <-