Pedro Alencar
Pedro Alencar

Reputation: 1089

Add abline to facet_zoom in ggplot2

I have a data set that looks like this

data <- data.frame(x = log(runif(100, min = 1, max = 10)), 
                   y = log(runif(100,min = 1, max = 10)))

When I plot using the code below I get an error (Error in scale_index[[i]] : subscript out of bounds)

ggplot(data, aes(x = x, y = y))+
  geom_point()+
  facet_zoom(x = x >2 & x < 3, y = y >2 & y < 3)+
  geom_abline(intercept = 0, slope = 1, color="black", linetype="dashed", size=0.5)

Ploting without the abline it works fine, but I really want to add this abline (identity line) without using some image edition efterwards.

enter image description here

What I would like is to have this: enter image description here

I also wouldn't mind to have the line showing up in the main plot (out of the facet_zoom).

This is the error message I get (I'm using ggforce 0.3.3): enter image description here

Upvotes: 0

Views: 318

Answers (1)

Pedro Alencar
Pedro Alencar

Reputation: 1089

Solved.

aparently was a compatibility problem. I was using ggplot2 v3.3.4. Updating it to v3.3.5 solved the issue.

Upvotes: 1

Related Questions