QuantLearner
QuantLearner

Reputation: 73

Creating a customised plot in ggplot2

I wanted a customized plot whose X-axis is the experiment number and there is a box plotted for every experiment. The height of the box is determined by two values (ymin and ymax) and the width of the box is same for all experiments.

I have tried to make such a plot using 4 geom_segment commands as follows

geom_segment(aes(y = open, yend = open, x = Exp - width / 4, xend = Exp + width / 4 )) +
geom_segment(aes(y = close, yend = close, x = Exp - width / 4, xend = Exp + width / 4 )) +
geom_segment(aes(y = pmin(open,close), yend = pmax(open,close), x = Exp - width / 4, xend = Exp - width / 4 )) +
geom_segment(aes(y = pmin(open,close), yend = pmax(open,close), x = Exp + width / 4, xend = Exp + width / 4 )) 

where Exp=experiment number and width=1

Please find attached the plot. However I think There should be a better method than this. Customised Plot

Upvotes: 2

Views: 71

Answers (1)

Lahiru Jayakody
Lahiru Jayakody

Reputation: 5400

Yes. it easy to do with

geom_rect

geom_rect function doc

Upvotes: 3

Related Questions