I'm trying to create a plot in R using ggplot2 and ggforce that contains an ellipse. Inside this ellipse, I want to fill a specific area the area (e.g., where x>0 and y>0) with blue color.
Here's some code that draws the ellipse but doesn't but without the filling:
library(ggplot2)
library(ggforce)
# Generate ellipse data for ggforce
ellipse_data <- data.frame(
x0 = 0,
y0 = 0,
a = 2,
b = 3,
angle = 0
)
ggplot() +
geom_ellipse(data = ellipse_data,
aes(x0 = x0, y0 = y0, a = a, b = b, angle = angle),
fill = NA, color = "black") +
coord_fixed() +
xlim(-3, 3) +
ylim(-3, 3)
This is what I expect:
The solution should work for any ellipse and other specific areas, e.g., x > 1 and y > 0.5
