Questions tagged [geom-hline]
59 questions
30
votes
3 answers
How to produce different geom_vline in different facets in R?
I am trying to produce 2 different geom_vlines with different colours in 2 different facets of a dataset. I am doing this to highlight means of 2 different facets.
Here's the dataset:
Pclass Sex Age SibSp Parch Fare Cabin Embarked …

Scott Grammilo
- 1,229
- 4
- 16
- 37
25
votes
1 answer
How to add a legend to hline?
I'd like to add a legend to hline plot.
The head of my subset looks like this
Site Date Al
1 Bo6 2014-10-07 152.1
2 Bo1 2014-10-07 157.3
3 Bo3 2014-10-07 207.1
4 Bo4 2014-10-07 184.3
5 Bo5 2014-10-07 23.2
13 Bo6 2014-10-14 …

LucySHE
- 387
- 1
- 3
- 9
5
votes
3 answers
How to draw a horizontal line and a vertical line that cross at the intersection with the line of a plot with ggplot2?
I made a plot with points connected with a line. In this plot I want to draw a vertical line from a point on the x-axis to the intersection with the plot line.And at the intersection, I want to draw a horizontal line to the Y-axis. I have searched…

Daniel Valencia C.
- 2,159
- 2
- 19
- 38
5
votes
3 answers
R ggplot: "cross effect" in legend (not going away with show.legend = NA)
The following code causes an unwanted cross effect in the legend.
ggplot() +
geom_vline(aes(xintercept=1,colour="vertical"), show.legend = NA) +
geom_hline(aes(yintercept=1,colour="horizontal"), show.legend = NA)
I read several posts which…

Frank
- 541
- 1
- 6
- 18
3
votes
1 answer
Add geom_hline to legend
After searching the web both yesterday and today, the only way I get a legend working was to follow the solution by 'Brian Diggs' in this post:
Add legend to ggplot2 line plot
Which gives me the following code:
library(ggplot2)
ggplot()+
…

Jesper.Lindberg
- 313
- 1
- 5
- 14
3
votes
1 answer
Polar plot (ggplot2), outer ring removed, grid on top
I've searched and re-searched through the different questions and although I've seen similar ones (some very helpful indeed) I can't seem to find an answer for this.
I'm working with polar plots, by default these plots add an extra outside ring…

Ana Ruiz Frau
- 71
- 3
3
votes
2 answers
ggplot: Add different lines in each facet of geom_bar
This questions is following my previous question:
How to ordering bars within all facets?
I want to add different lines in each facet of my geom_bar. I used the geom_hline function, but all lines are added in all facets!
My code:
i <-…

Ph.D.Student
- 704
- 6
- 27
3
votes
1 answer
geom_hline or geom_vline does not seem to accept vector for reference line, if called inside a function and facet_grid() is used
I have been facing issue with geom_hline or geom_vline if I call it under custom function and it takes the value from a vector. It seems to work fine until I add facet_grid() within that function body.e.g
Without Function
c<- data.frame(A =…

Sana Ali
- 165
- 1
- 11
2
votes
3 answers
How to avoid the crossing effect in legend with geom_vline() and geom_hline on the same scatter plot?
I created a scatter plot with geom_hline() and geom_vline(), the plot is good but the legend entries are not how I would like to make them appear. The vline (Restauration) and hline (Threshold) are crossing each other in the legend, making it…

Jude
- 153
- 2
- 8
2
votes
1 answer
Creating legends for several geom_hlines while using gghighlight
I want to create a legend for my horizontal lines in geom_hline. The data I am using comes from 3 different dataframes. I am also using gghighlight, I believe that it masks any legend. How do I force a legend in that case?
The 3 dataframes are:
1)…

cyws
- 35
- 1
- 6
2
votes
2 answers
How to pass hex codes to geom_hline in ggplot?
In the code below I create a ggplot, p1, using data from df1. I would like to add a horizontal line at the score value for each item in df2, and colour each line using the corresponing hexcode for each item, contained in column item_hexcode.
I…

monkeytennis
- 848
- 7
- 18
2
votes
1 answer
Facetting with factorised variables and geom_hline / geom_vline
Consider this code:
require(ggplot2)
ggplot(data = mtcars) +
geom_point(aes(x = drat, y = wt)) +
geom_hline(yintercept = 3) +
facet_grid(~ cyl) ## works
ggplot(data = mtcars) +
geom_point(aes(x = drat, y = wt)) +
…

tjebo
- 21,977
- 7
- 58
- 94
2
votes
3 answers
How do i make an errorbar for a geom_hline using geom_ribbon in ggplot2?
I want to have an error bar for my geom_hline and thought that a geom_ribbon with opacity would look best. but i cant figure out how to make it reach the ends of the plot. I want the geom_ribbon to touch the sides of the plot as the geom_hline does.…

Fponken
- 23
- 3
2
votes
1 answer
How can I efficiently create a manual legend when using a loop to create multiple geom_hline objects in a facet?
I have scripted the below example to illustrate my question.
I wanted to create my own custom legend and colour scheme for each geom_hline I plot. I could achieve this by using this answer Construct a manual legend for a complicated plot.
However, I…

DataJack
- 341
- 2
- 13
1
vote
1 answer
add different geom_hline to different facet
I have the following code:
install.packages("tidyverse")
library("tidyverse")
data(diamonds)
ggplot(data=diamonds)+
geom_point(mapping=aes(x=carat,y=price),color="blue")+
geom_hline(aes(yintercept=max(price)),
color="seagreen")+
…

Kiki Liu
- 27
- 3