Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201867

How do I fill the space between multiple line segments in ggplot?

$
0
0

Suppose I have the following plot in ggplot2:

p <- ggplot() +
  geom_point(aes(x=15,y=50),shape=19,fill="gray0", size=5)+
  geom_point(aes(x=28, y=75),shape=19, fill="gray0", size=5)+
  geom_point(aes(x=13, y=100),shape=19, fill="gray0", size=5)+
  geom_segment(aes(x = 15, y = 50, xend = 28, yend = 75), size=1)+
  geom_segment(aes(x = 13, y = 100, xend = 28, yend = 75), size=1)+
  geom_segment(aes(x = 15, y = 50, xend = 13, yend = 100), size=1)

This plots three line segments intersecting at common points so that a triangle is created. How would I then fill the formed triangle with a color?


Viewing all articles
Browse latest Browse all 201867

Trending Articles