0
votes

I have a dataframe of which two columns are of date and sales. date column varies from 2012-10-22 to 2016-09-22. I want to plot the graph of sales in jan 2013 by day without creating any subset.

I have used this- ggplot(subsales,aes(Date,spdby))+geom_line()

Is it possible by using ggplot()?

I have plotted the sales per day and look like this-

I want to zoom in, to January 2013 and want to extract that part as a new plot.

1
Yes it is! Try scale_x_date() or xlim()! - Roman
but, I want to plot only dates of jan 2013 from the span of 5.5 years - Ankit Gupta
Then use different alpha values, eg. 0 and 1. It would be much more easier to help if you add a small reproducible example to your question - Roman

1 Answers

0
votes

yes, in ggplot:


library(ggplot2)

subsales <- data.frame(
  date = seq(as.Date("2013-1-1"), as.Date("2017-1-1"), by = "day"),
  spdby = runif(1462, 2000, 6000)
)

ggplot(subsales, aes(date, spdby)) + 
  geom_line()

ggplot(subsales, aes(date, spdby)) + geom_line() + 
  scale_x_date(limits = c(as.Date("2013-1-1"), as.Date("2013-1-31")))
#> Warning: Removed 1431 rows containing missing values (geom_path).