Questions tagged [geom-hline]
59 questions
1
vote
1 answer
How to specify geom_hline color AND linetype in ggplot legend?
I'm using hlines to visualize screening level thresholds while displaying four categorical variables and one numeric variable. I want to display both a different linetypes AND color for each threshold hline in the plot and in the legend. I can make…

Beka Stiling
- 25
- 1
- 7
1
vote
1 answer
How to add a label to horizontal line in ggplot 2 when x-axis is date?
I am trying to graph a temperature dataset using mean, max, and min temps by month over 2 years. The graph includes two horizontal temperature thresholds.
I have succeeded in creating a graph, but I want to add labels "9.9" and "12.97" to my 2…

steph
- 13
- 4
1
vote
1 answer
How to add a label to the x / y axis whenever a vertical / horizontal line is added to a ggplot?
The x and y axis are labeled based on certain interval set by ggplot.
In the event that a horizontal or vertical line is added to the plot, the goal is to label x or y axis at the exact value of the line.
How can this be done?

Bear Bile Farming is Torture
- 4,317
- 4
- 27
- 61
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
1
vote
2 answers
how to add and edit a legend in goem_hline() in R
I'm trying to add a caption to geom_hline () but I don't know how I can do it.
I tried geom_hline (aes (yintercept = 18, 'Historical serie'), size = 1.5, col =" # ffff00 ") but it returns an error. I took 'Historical serie' it worked, but the…

wesleysc352
- 579
- 1
- 8
- 21
1
vote
1 answer
How can I add legend to multiple hlines in ggplot2?
Can anyone help me out with some task?
I have to add 3 geom_hline() to a plot.
One of them is a line that shows the recommended spacing for threes in a forest, and the others are the acceptable upper and lower limits of variation in spacing.
To…

caio.valente14
- 67
- 9
1
vote
1 answer
Plotting vertical/horizontal lines that intersect line graph on ggplot
The following code produces the following plot:
time_step <- c(1:5, 1:5)
perceived_signal_slow <- c(1:5, cumsum(1:5))
signal_name <-…

codegoblin1996
- 302
- 2
- 12
1
vote
1 answer
Adding a horizontal line to a scatterplot in ggplot2
Following on from this
How to add the results of applying a function to an existing data frame?
library (tidyverse)
library (epitools)
# here's my made up data
DISEASE = c("Marco Polio","Marco Polio","Marco Polio","Marco Polio","Marco Polio",
…

damo
- 463
- 4
- 14
1
vote
1 answer
geom_hline with multiple points and facet_wrap
i am trying to plot horizontal lines at specific points of my data. The idea is that i would like a horizontal line from the first value of equivalent iterations(i.e 0) at y intercept for each of my axis; SA, VLA, HLA. My question will become…

Kostas
- 13
- 3
1
vote
1 answer
Legend geom_hline not in right order
I've made a barplot in ggplot, and added a couple of lines. What happens is that the color and description of the lines don't correspond:
The yellow line should have the description 'Median Member', but is displayed as 'avg Member'. What happens…

Alfred
- 13
- 2
1
vote
2 answers
Add mean line in the legend based on groups - geom_hline
I would like to add a legend to my plot. The problem I have been struggled with is that I can not display mean line in the legend. Instead I have a point with a line based on the type.
What I would like to get in the legend is dots for WT/SHC and…

magruc
- 165
- 1
- 11
1
vote
0 answers
ggplot2 horizontal line with facet_grid boxplot
I have a data frame with 4 variables. I plotted the 4 variables using boxplot and facet_grid(intg~del)
D = read.table('data.dat')
names(D) = c('size','mut','intg','del')
ggplot(D,aes(x=mut,y=size,fill=as.factor(mut))) +
geom_boxplot() +…

AWRAM
- 333
- 2
- 16
1
vote
1 answer
R ggplot2 color mapping with geom_hline
I am trying to map color variable to geom_hline, but doesn't seem to work like other geometries. Neither of these work, in each case, rendering a fixed black line.
ggplot(data.frame(x=0,y=0,series="ABC"),aes(x,y,color=series))) +
geom_point() +
…

Nicholas Hamilton
- 10,044
- 6
- 57
- 88
0
votes
1 answer
How to add horizontal lines for different facets in ggplot2
I want to add horizontal line to a facetted barplot using ggplot2.
I have two nutrient types, each with a different guideline value I would like to display and I want the plots to appear side by side in a single frame.
Data looks like this:
Trip …

Lindsey
- 1
- 1
0
votes
2 answers
Error: object 'i' not found in geom_hline and geom_vline
I want to make a scatter plot with a horizontal and a vertical line. The lines shall appear at the mean of the x and y variable. What I do is:
# Some data
df <- data.frame(x= rnorm(100), y= rnorm(100))
df$i1 <- mean(df$x)
df$i2 <- mean(df$y)
#…

LulY
- 976
- 1
- 9
- 24