Questions tagged [geom-vline]
59 questions
9
votes
1 answer
ggplotly() does not display geom_vline / geom_hline when data is POSIXct
I am trying to make a graph with "time markers". These time markers are vertical lines for certain dates. Time data are POSIXct format. I would like to use the awesome interactive interface of Plotly and use my ggplot objects in it.
The problem is…

Paul
- 2,850
- 1
- 12
- 37
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
2 answers
Extend geom_vline outside of plot
I am trying to expand the geom_vline lines in my ggplot plot to go outside of the plot space and into the axis area. The goal of this is to have these lines separating the axis labels so it can line up with another plot that goes next to it (see…

m.evans
- 606
- 3
- 15
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
2 answers
Create geom_vline for mean value in a density plot, for a new variable in the dataframe, without create new tables
Here I am looking at the mtcars dataset.
I create a density plot for the wt variable using the ggplot2 package. I also the geom_vline() layer to add a vertical line for the mean of wt.
ggplot(mtcars, aes(x = wt)) +
geom_density() +
…

hachiko
- 671
- 7
- 20
3
votes
0 answers
Add a legend for multiple geom_vline in facet_wrap
I am trying to add a legend for multiple geom_vlines in a facet_wrap, but I can't manage to keep the colors in the graphs.
I have added aes on each vline, but they appear grey.
ggp +
geom_vline (aes(xintercept = median(overall_vector), color =…

Xavier
- 129
- 7
3
votes
1 answer
Mark a period of time in a time-series-plot
First, let's create some fake data:
d <- c("2019-01-01", "2019-01-02", "2019-01-03", "2019-01-04", "2019-01-03", "2019-04-06", "2019-04-03", "2019-05-07", "2019-05-03", "2019-05-03", "2019-05-03", "2019-05-03", "2019-06-03", "2019-06-03",…

D. Studer
- 1,711
- 1
- 16
- 35
2
votes
1 answer
Adding vlines to a density plot in Shiny
I am trying to add vlines to a density plot in shiny for R. For reproducible purposes, I will use the iris data set. The data is clustered using kmeans from the cluster package. Outliers are located by measuring distances from the centers of…

Melissa
- 25
- 3
2
votes
0 answers
Can geom_vline be connected across facet_grid?
I am using geom_facet to visualize data across different samples. I calculate a set of percentiles beforehand for every sample and supply these values to geom_vline via a separate tibble.
This allows to plot the percentiles of every sample…

MaBar1
- 33
- 5
2
votes
0 answers
change linetype in legend for geom_vline()
I want to do a graph where I use 4 geom_vlines with differents linetypes, but in the legend the linetype isn't right. How can I make the linetype of the legend fits with the linetype of the vline?
ps: I have abbreviate the dataframe because it's…

helodambrat
- 21
- 2
2
votes
3 answers
How to use loop with geom_vline and facet_wrap?
I have data similar to the one I've created below:
set.seed(42)
dates <- seq.Date(as.Date("2012-08-01"), as.Date("2014-08-30"), "day")
n <- length(dates)
dat <- data.frame(date = dates,
category = rep(LETTERS[1:4], n/2),
…

AneesBaqir
- 423
- 1
- 12
2
votes
2 answers
In R ggplot2 ,how to draw vertical lines automatically
In R ggplot2 ,how to draw vertical line between columns
Using 'geom_vline(xintercept=as.numeric(plot_data$mperiod)+0.5)' ,it's can't work
plot_data <- data.frame(mperiod=paste0('Q',1:4),amount=c(1:4))
plot_data %>% ggplot(aes(x=mperiod,y=amount))+
…

anderwyang
- 1,801
- 4
- 18
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
How to add vertical lines and annotation to survival plot with risk table (R)
I want to have a survival plot with a risk table with a vertical line at 12 months and 36 months. Initially I was able to go this
figure1$plot + geom_vline(xintercept = 12) + geom_vline(intercept = 36)
However when I want to add the risk table as…

user2930701
- 163
- 1
- 1
- 5
2
votes
2 answers
How to get a vertical line in a scatter polar coordinates plot in R using ggplot2
I have two questions:
Hopefully a simple question, but I want to put a vertical line in my polar coordinates graph that denotes the start of the data. I have a data set that collects hourly readings over the period of a year and I have managed…

Dustin
- 139
- 9