57 questions
1
vote
2
answers
40
views
Is it possible to create a geom_segment with a gradient between two colors, but the start/end colors change depending of a variable?
I'm building a plot with a discrete Y-axis with multiple pairwise comparisons. However, instead of using text for the labels, I created a secondary plot with color points indicating the 2 groups ...
0
votes
1
answer
29
views
How to create geom_segment() plot on Date x-axis using plotnine in python?
Not able to figure out how to use geom_segment() on Date x-axis in python by using plotnine. Have tried some code but getting error:
import pandas as pd
from plotnine import ggplot, aes, geom_segment
...
1
vote
1
answer
28
views
Adding arrowheads to errorbars in ggplot2 in R where they go above or below limits
I am using ggplot2 in R and I am trying to add arrowheads to the errorbars on my plot only where the errorbar goes above or below the upper_limit/lower_limit in the plot below (see code for limit ...
0
votes
2
answers
63
views
Draw geom_segment that crosses zero in ggplot2 coord_polar
I am modifying this tutorial to create a circular calendar of a year. I am trying to subdivide the calendar into seasons, but because the geom_segment for winter crosses zero degrees on my polar plot, ...
1
vote
1
answer
24
views
ggplot2 Custom Geom Line Glyphs Incorrect
Background
I am developing a custom geom for ggplot2 in R that starts by building on geom_segment():
geom_custom <- function(mapping = NULL, data = NULL,
stat = "identity&...
1
vote
1
answer
91
views
Order y-axis using geom_segment()
I'm building a plot with mostly geom_segment(), and I'm having trouble ordering the y-axis as I need. I know this question is somewhat repeated, and I apologize for that, but I just can't understand ...
0
votes
1
answer
69
views
ggplot2 - how to keep the legend items with the same size, when geom_segment() has different sizes? [duplicate]
I'm plotting several segments as once using ggplot2, with two different sizes.
An example of what I want to do is provided in one of the answers here. Here's the example they provide:
ggplot2::ggplot()...
1
vote
1
answer
37
views
Plot arrow outside of figure instead of inside
I am trying to plot the arrow outside of the figure. I have tried a number of different options, but they keep plotting the arrow inside the figure. Is there a way to plot it outside the bounding box?
...
0
votes
2
answers
56
views
Changing axis tick marks for geom_segment() with time data
I have a dataset with measures at multiple timepoints, with the expected time vs. actual time is the measurement took place. I'm trying to display the difference in the expected vs. the actual time ...
0
votes
1
answer
54
views
Decrease space from y-axis after adding geom_segments to geom_violin plot
I have been trying to plot some data with geom_violin and add two geom_segments on each side of the plot. I would like to reduce the space between the violins and the y-axis, which increases when I ...
0
votes
1
answer
47
views
Adding segments to a geom_polygon ggplot
I have a data.frame where each row defines a composition of a group, and I would like to plot them all as pie charts on a cartesian plane.
Here is the example composition data.frame:
library(dplyr)
...
1
vote
0
answers
71
views
Arrow tips on geom_segment in ggplot2 are slightly offset. How do I fix this?
I am setting up a plotting space for a scatterplot and I am trying to add axes with arrowed tips using the geom_segment function in ggplot2.
This is the code I have so far:
Max <- 5;
xaxis1 <-...
0
votes
1
answer
231
views
How to add PCA Loadings to ggplot?
I have created the PCALoadings using PCAloadings <- data.frame(Variables = rownames(pca_res_t$rotation), pca_res_t$rotation) but can't seem to actually add the loadings onto my ggplot. I'll post ...
0
votes
2
answers
39
views
geom_segment does not print corresponding to i'th value in plots generated by for loop
I am using a for loop to produce plots based on the same code but with different values.
This is my current plot:
As you can see, the horizontal geom_segment()-lines are printing on the exact same y-...
0
votes
0
answers
164
views
geom_curve with variable linewidth
Thanks to @jared_mamrot, proposes gg_arrow. Now I need to combine gem_curve with gg_arrow.
Here is a sample code of gg_arrow:
install.packages("devtools")
devtools::install_github("...
1
vote
1
answer
86
views
Is there an R function to dodge overlapping values in a geom_segment plot?
I have this data:
"","NAME","PRE","start","end","jit"
"1","A","Treatment A",2024,2024.5,0
"2","...
0
votes
1
answer
139
views
Phase diagram with vertical lines connecting discrete phases or states
I draw a state diagram using ggplot2 in R. The discrete vertical axis shows several states, and the horizontal axis shows time. Lines connect the start and end points of a phase, with different ...
0
votes
2
answers
542
views
Add leading lines / geom segment to pie graph with ggplot2
I have a pie graph that I've generated with ggplot2. However, some of the wedges are quite thin, so I wanted to place the annotations outside the pie graph and add leading lines. I've succeeded in ...
0
votes
2
answers
67
views
How to deal with time series data to create new x and y axis lines to ggplot graph?
I'm trying to present a ggplot graph similar to Base R graphs. The issue I have is dealing with time series data (date and time) to draw the x and y axis properly.
I used the same approach provided by ...
0
votes
2
answers
130
views
geom_segments of different size produce weird legend
I have a figure with geom_segments of different size. The legend superposes dashes and dots of different sizes. How to prevent that?
Reproductible example:
dataframe = data.frame(country = c("...
1
vote
1
answer
79
views
Creating a Grouped Cleveland Plot
I want to make a cleveland style chart that allows the comparison of the probability of exhibiting behaviors by age compared between males and females. I have a dataset similar to this:
Data <- ...
0
votes
1
answer
59
views
ggplot2 not printing the colours specified inthe dataframe and set as factor levels
I am trying to reproduce a map from W.E.B DuBois with the original colors and values with thin black arrows in each state starting at the bottom right corner of the state polygon and pointing to the ...
0
votes
0
answers
68
views
How link two variable for one individual in ggplot2?
I have an issue on how to display segment with geom_segment in ggplot graph. I have individuals which are measurements on height and body mass related to Age, and after making a plot I would like to ...
2
votes
2
answers
73
views
Add vertical line segment at given x extending between intercepts of two regression lines
I want to add a vertical line at days==0 that extends from the value of y where days==0 among x==0, to the value y where days==0 among x==1.
df <- structure(list(y = c(3, 4, 4, 3, 4, 4, 4, 3, 4, 4,...
1
vote
1
answer
2k
views
Trying to make a segment graph in ggplot2, geting an error; no applicable method for 'rescale' applied to an object of class "character"
I am trying to create a plot in ggplot2 showing the results of environmental sampling conducted over time. My data set has deployment and retrieval dates for samplers and the result of PCR on the end ...
0
votes
1
answer
446
views
Adding Consecutive Arrows to geom_point() in ggplot2
I want to add a series of arrows connecting each observation in geom_point as in the graph:
I understand that geom_segment is meant to be used, but I am having issues, and have not found something ...
0
votes
1
answer
322
views
ggplot segments with dash dash/ vertical line
I am doing a plot similar to this idea
library(ggrepel)
library(ggplot2)
name<-c("A1","A2","A3","A4","A5","A6","A7","A8&...
0
votes
1
answer
340
views
R: Hide geom_segment() if a certain condition is true?
I use geom_segment() from ggplot2 package in R, where the data attribute is a vector with two elements. The segment is an arrow. I want to hide the segment if one of the elements of the data vector ...
1
vote
1
answer
93
views
Problem with plot in R: reducing spce within labels and bars, but x axis ticks disappear
I have the following code with its corresponding plot:
ggplot(df2, aes(x=Fecha.inicio, xend=Fecha.final, y=Ministro.a, yend=Ministro.a, color=Presidente)) +
theme_minimal()+ #use ggplot theme with ...
0
votes
0
answers
16
views
Dodge Effect with geom_segment [duplicate]
I have the following dataset where I am visualizing a range comparison for different features between two model types in ggplot2 with geom_segment.
test <- data.frame("var" = c("...
1
vote
1
answer
1k
views
Add linetype to geom_segment legend
Aim: add the linetypes of the segments to the legend, as well as the colour.
Problem: only the colour is showing.
Data:
m = as.data.frame(matrix(c(1:10), ncol = 2, nrow = 10))
Plot:
ggplot(m, aes(v1,...
0
votes
1
answer
819
views
Adjust yend in geom_segment when x is categorical
I would like to adjust the vertical position of the geom_segment when x is categorical. In the example below the geom_segment is centered around the variable on the x-axis.
I would like draw the ...
1
vote
1
answer
648
views
How to create multiple lines with arrows in geom_segment
I am trying to create a graph that looks like the example below. Namely, I am looking to add arrows that point in the direction of movement from 2019 to 2021.
I have the following example dataset:
...
3
votes
1
answer
907
views
geom_segment not recognising factored x-axis
Aim: produce a bar plot representing a time series of measurements (variables) taken at 14 Sites (factors), including drawing horizontal lines to demonstrate benchmark levels for each site.
Problem: ...
2
votes
1
answer
404
views
How to change the linetype of a segment more than once in R using ggplot
Following the guidance presented in a previous post, I attempted to extend the solution to a dataset where the significant "Change" in grades (of 3 or more points) may be present at ...
1
vote
2
answers
431
views
How to apply a continous color ramp to a straight line in ggplot2?
I have would like to apply a continous color ramp to a vertical line in ggplot2. My plot is below. I have applied the continous color ramp to the geom_line() element, while the horizontal lines ...
5
votes
2
answers
4k
views
Connect stack bar charts with multiple groups with lines or segments using ggplot 2
I am conducting a study of a number of patients with a disease, and using an ordinal scale assessment of functional status at 3 different time points. I want to connect multiple groups in stacked bar ...
0
votes
1
answer
644
views
Slightly change geom_segment's position of x only, but keep position of xend constant
I want to draw a bar chart with three columns, where two arrows start from one column to the other two columns and these arrows do not overlap each other, as shown below.
I managed to produce the ...
1
vote
0
answers
119
views
ggplot2 can I stack horizontal goem_segments?
The code below produces a gantt chart, time on each project by person. It's done in two layers where the black bars are 100% of a persons time and the coloured bars represent time on projects.
What I'...
0
votes
1
answer
3k
views
ggplot2 geom_point with aes fill only displays black
I'm having trouble displaying different fill colors with geom_point, only black shows up. I know I can use color to show different colors but it doesn't seem to work well with geom_segment. Here is an ...
3
votes
1
answer
1k
views
Plotting geom_segment with position_dodge
I have a data set with information of where individuals work at over time. More specifically, I have information on the interval at which individuals work in a given workplace.
library('tidyverse')
...
2
votes
1
answer
232
views
geom_segment() doesn't store object value defined inside a for loop
I defined a very simple for loop in which I plot a normal distribution with a vertical red line and a smaller vertical black segment. The normal distribution doesn't change, but the position of the ...
2
votes
2
answers
202
views
How to weight and label arrows created in geom_segment using another variable
Consider this dataframe:
data <- data.frame(ID = rep(1, 6),
Loc = c("A","B","D","A","D","B"),
...
-1
votes
1
answer
665
views
Geom_segment not reading missing aesthetics: x, y, xend and yend Piper Plot
I am trying to reproduce the Piper plot here: https://github.com/markolipka/ggplot_Piper however I keep getting the error:
Error: geom_segment requires the following missing aesthetics: x, y, xend and ...
0
votes
1
answer
634
views
Adding a gap in geom_segment in ggplot2
I have some data with id, time_to_event, event, therapy start and therapy stop variables.
Here is a reproducible example:
data <- structure(list(id = structure(c(1L, 3L, 9L, 2L, 5L, 10L, 7L,
8L, ...
0
votes
0
answers
388
views
geom_segment reaching over multiple facets
I am trying to draw a line with R's ggplot that starts on one facet and ends on another.
I believe this question was not asked yet (at least I could not find it) but I have found some example code ...
0
votes
1
answer
605
views
Can ggplot2 geom_segment size be specified as a proportion of the axis size?
I have a geom_segment in a plot and would like its size to scale relative to the y axis.
For example:
iris %>%
group_by(Species) %>%
summarise(avg_sepal_length = mean(Sepal.Length)) %>%
...
4
votes
2
answers
440
views
geom_segment line vertical for multiple variable plot
The plot code below makes the segment line congverge at the center of the descrete x variable for all colours. What can be done so that the segment line is vertical for each x variable respective of ...
0
votes
1
answer
220
views
geom_segment - parallel dodging
I am having a 'classical' ggplot problem, very similar to the question discussed here. I tried to solve it like suggested there, but somehow it does not work.
The dataset is:
overall <- structure(...
1
vote
1
answer
275
views
How can I make this ggplot render more quickly?
Below is a reprex of the data I'm working with. The geom_segment calls make the rendering very sluggish. Is there an alternate way to achieve the same result more quickly?
library(ggplot2)
library(...