Plot display errors with geom_hline/vline and ggplotly

My ggplotly() output is not displaying vertical and horizontal lines properly on graphs using geom_hline() and geom_vline(). The problem occurs whether I display the graph in R Studio or publish it to plotly using the plotly_POST command, and whether I am using my own data or the example code from the documentation. Here is an example of the code:

x1 <- factor(c('a', 'b', 'c'))
y1 <- c(1, 2, 3)
df <- data.frame(x1,y1)
ggplot(data=df, aes(x=x1, y=y1)) + 
  geom_bar(stat="identity") +
  geom_hline(yintercept=1.5)
p <- ggplotly()
plotly_POST(p, filename='NPL_bar')

The ggplotly output can be viewed here. There should be a horizontal line on the graph with y-intercept = 1.5, but what displays is a sloped line instead.


R Studio Desktop version:
platform x86_64-pc-linux-gnu
arch x86_64
os linux-gnu
system x86_64, linux-gnu
status
major 3
minor 2.3
year 2015
month 12
day 10
svn rev 69752
language R
version.string R version 3.2.3 (2015-12-10)
nickname Wooden Christmas-Tree

1 Like

I am having a similar problem.
If the x axis is posixct the problem is even worst: the x/y range becomes very very large and I have to zoom in a lot to see the graph.
Segment works for me though.
so for now, I’ll try that.

R version 3.2.3 (2015-12-10)
ggplot 2.0
Rstudio Version 0.99.491

PS: I can’t upload examples because I’m behind a firewall.

It works fine in RGui or in Emacs using ESS using p <- ggplot(data=df etc and then plot(p) instead of p <- ggplotly (see out below). If RStudio is giving you a sloped hline then maybe the problem is specific to RStudio?

This post is specifically for plotly. ggplot works fine, as usual