ggrepel

Repel text from edges in network

柔情痞子 提交于 2021-02-18 22:23:06
问题 When drawing a network, it would be nice if the labels of the nodes could also avoid network edges. E.g. in the example below, it would be possible to move all the labels outside the network. I've tried several packages, but so far have not found even a hacky way to do that. Is there a way? Example below: library(ggraph) library(tidygraph) reprex <- tibble(to = sample(1:10, 100,replace=T), from = sample(1:10, 100,replace=T) ) %>% as_tbl_graph() V(reprex)$label1 <- rep("label",10) reprex_plot

Repel geom label and text in ggplot. And ordering geom points based on size

江枫思渺然 提交于 2021-02-10 06:35:09
问题 I have 2 data frames such as these: df1 <- data.frame( party = c("Blue Party", "Red Party"), dim1 = c(0.03, -0.04), dim2 = c(-0.05, 0.02), sz = c(34, 42) ) df2 <- data.frame( var = c("Economic", "Gov trust", "Inst trust", "Nationalism", "Religiosity"), dim1 = c(0.1, -0.5, 0, 0.6, 0.4), dim2 = c(0.1, 0.6, 0, 0, 0.3) ) I want to plot the parties from df1 as points defined by size and include arrows based on df2 on the same graph. I've used ggplot to do this: ggplot(df1, aes(x = dim1, y = dim2,

Move labels from geom_label_repel into ggplot margin

孤者浪人 提交于 2021-02-04 19:17:45
问题 In the plot below I'd like to move the label "V-Engine" into the plot margin. Adjusting the nudge_x argument is moving the "S-Engine" label but not the "V-Engine" label. library(ggplot2) library(ggrepel) library(dplyr) ds <- mtcars %>% mutate(vs = factor(vs, labels = c("V-Engine", "S-Engine"))) %>% # Create labels for the rightmost data points group_by(vs) %>% mutate( label = case_when( wt == max(wt) ~ as.character(vs), TRUE ~ NA_character_ ) ) %>% ungroup() ds %>% ggplot(aes(x = wt, y = mpg,

Move labels from geom_label_repel into ggplot margin

我只是一个虾纸丫 提交于 2021-02-04 19:17:28
问题 In the plot below I'd like to move the label "V-Engine" into the plot margin. Adjusting the nudge_x argument is moving the "S-Engine" label but not the "V-Engine" label. library(ggplot2) library(ggrepel) library(dplyr) ds <- mtcars %>% mutate(vs = factor(vs, labels = c("V-Engine", "S-Engine"))) %>% # Create labels for the rightmost data points group_by(vs) %>% mutate( label = case_when( wt == max(wt) ~ as.character(vs), TRUE ~ NA_character_ ) ) %>% ungroup() ds %>% ggplot(aes(x = wt, y = mpg,

Using ggrepel and shadowtext on the same geom_text

自作多情 提交于 2021-01-28 00:14:32
问题 I have a plot (made in R with ggplot2 ) that's the result of some singular value decomposition of a bunch of text data, so I basically have a data set of ~100 words used in some reviews and ~10 categories of reviews, with 2D coordinates for each of them. I'm having trouble getting the plot to look legible because of the amount of text and how close together a lot of the important points are. The way my data is structured now, I'm plotting 2 different geom_texts with different formatting and

Getting coordinates for the label locations from ggrepel

為{幸葍}努か 提交于 2021-01-19 06:28:11
问题 Below is an example of "label location optimization" using ggplot2 and ggrepel: x = c(0.8846, 1.1554, 0.9317, 0.9703, 0.9053, 0.9454, 1.0146, 0.9012, 0.9055, 1.3307) y = c(0.9828, 1.0329, 0.931, 1.3794, 0.9273, 0.9605, 1.0259, 0.9542, 0.9717, 0.9357) ShortSci = c("MotAlb", "PruMod", "EriRub", "LusMeg", "PhoOch", "PhoPho", "SaxRub", "TurMer", "TurPil", "TurPhi") df <- data.frame(x = x, y = y, z = ShortSci) library(ggplot2) library(ggrepel) ggplot(data = df, aes(x = x, y = y)) + theme_bw() +

Getting coordinates for the label locations from ggrepel

不想你离开。 提交于 2021-01-19 06:24:25
问题 Below is an example of "label location optimization" using ggplot2 and ggrepel: x = c(0.8846, 1.1554, 0.9317, 0.9703, 0.9053, 0.9454, 1.0146, 0.9012, 0.9055, 1.3307) y = c(0.9828, 1.0329, 0.931, 1.3794, 0.9273, 0.9605, 1.0259, 0.9542, 0.9717, 0.9357) ShortSci = c("MotAlb", "PruMod", "EriRub", "LusMeg", "PhoOch", "PhoPho", "SaxRub", "TurMer", "TurPil", "TurPhi") df <- data.frame(x = x, y = y, z = ShortSci) library(ggplot2) library(ggrepel) ggplot(data = df, aes(x = x, y = y)) + theme_bw() +

Aligning ggrepel labels

笑着哭i 提交于 2020-07-20 03:46:40
问题 I have a script that downloads a bunch of COVID data about the area surrounding some Air Force bases and produces a chart. I was going to try to reproduce it using a big dput() but it's too many characters for a post. The dput() to reproduce the data frame can be copied from here. The data itself looks like head(smDailyBaseData) DaysSince Base abbv newRate label <drtn> <chr> <chr> <dbl> <chr> 1 7 days Edwards EdwardsAFB 0 "Edwards \n 0" 2 8 days Edwards EdwardsAFB 0.00000140 "Edwards \n 2" 3

Aligning ggrepel labels

扶醉桌前 提交于 2020-07-20 03:46:05
问题 I have a script that downloads a bunch of COVID data about the area surrounding some Air Force bases and produces a chart. I was going to try to reproduce it using a big dput() but it's too many characters for a post. The dput() to reproduce the data frame can be copied from here. The data itself looks like head(smDailyBaseData) DaysSince Base abbv newRate label <drtn> <chr> <chr> <dbl> <chr> 1 7 days Edwards EdwardsAFB 0 "Edwards \n 0" 2 8 days Edwards EdwardsAFB 0.00000140 "Edwards \n 2" 3

Wrap long text in a text box

泄露秘密 提交于 2020-01-13 19:28:07
问题 I have the following reproducible coefficient plot. library(tidyverse) tribble(~term, ~estimate, ~lower, ~upper, ~text, "a", .25, .2, .3 , "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur sit amet orci vel dolor luctus auctor sed non lacus. Cras malesuada, tortor ac mattis rutrum, dui erat aliquam ipsum, id.", "b", -.25, -.3, -.2, "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur sit amet orci vel dolor luctus auctor sed non lacus. Cras malesuada, tortor