Skip to content
Prev 386562 / 398502 Next

ggplot2 + coord_cartesian + automatic ylim

On 12/13/2020 12:49 PM, Brian Beckage wrote:
Brian,

I couldn't get your code to work, so I modified it slightly. Someone 
more adept at ggplot than me may be able to give you a better solution.

xmax<-AAPL$date[nrow(AAPL)]
xminmax <- c(xmax-weeks(10), xmax)
yminmax <- with(AAPL, range(AAPL[date>=xmin & date<=xmax,]$close))

AAPL %>%
 ? ggplot(aes(x = date, y = close)) +
 ? geom_line() +
 ? labs(title = "AAPL", y = "Closing Price", x = "") +
 ? coord_x_date(xlim=xminmax, ylim=yminmax) +
 ? theme_tq()


Hope this is helpful,

Dan