Questions tagged [geom-segment]
44 questions
4
votes
2 answers
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 charts across these time points.
I looked at…

XFrost
- 109
- 4
4
votes
2 answers
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 colour?
#~ Plot data
ggplot(data = data0, aes(x =…

altfi_SU
- 584
- 1
- 3
- 15
3
votes
1 answer
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')
library('lubridate')
# individual A
a_id <-…

PaulaSpinola
- 531
- 2
- 10
2
votes
2 answers
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, 4, 3, 4, 4,
4, 3, 3, 4, 3, 3, 4, 4, 4, 3, 4, 3,…

Eric Green
- 7,385
- 11
- 56
- 102
2
votes
1 answer
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 different months for different students, and that a Student could…

John Sandman
- 125
- 1
- 8
2
votes
1 answer
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 vertical line and the vertical segment are supposed…

nd091680
- 585
- 4
- 15
2
votes
2 answers
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"),
TimeDiff = c(NA, 4.5,2.2,2.1,3.4,7.2))
We have the same ID with observations at multiple locations (Loc). The…

Ryan
- 1,048
- 7
- 14
2
votes
1 answer
how to prevent an overlapped segments in geom_segment
I'm trying to map different ranges (lines) into different regions in the plot (see below) using geom_segment but some of the ranges overlap and can't be shown at all.
This is a minimal example for a dataframes:
start = c(1, 5,8, 14)
end =c(3, 6,12,…

Sam
- 309
- 2
- 10
2
votes
1 answer
R : ggplot2 geom_segment pixelized
When I use geom_segment it's pixelized compared to a geom_abline. When I export to pdf with ggsave it's not vectorized.
geom_abline :
geom_segment :
Any idea how to solve this ?
Thanks

Nicolas Rosewick
- 1,938
- 4
- 24
- 42
1
vote
1 answer
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","B","Treatment A",2026,2026.5,0
"3","C","Treatment A",2024,2024.5,0
"4","D","Treatment A",2026,2026.5,0
"5","E","Treatment…

UnsoughtNine
- 63
- 1
- 8
1
vote
1 answer
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 <- data.frame(
skill = c("Writes Name", "Reads 10…

KingCrawDad
- 11
- 1
1
vote
1 answer
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 product. I want to make a graph with a line for…

Seth Goodnight
- 25
- 1
- 4
1
vote
1 answer
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 black gridlines and white background
…

Ivan A. Ramírez Zapata
- 157
- 1
- 9
1
vote
1 answer
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:
structure(list(jurisdiction = c("Alabama",…

babybonobo
- 89
- 8
1
vote
2 answers
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 represent the limits of the range covered by the color…

ia200
- 255
- 1
- 9