Ewa Krzyszczyk
Ewa Krzyszczyk

Reputation: 11

ggplot2 scale_x_date limits 1-Jun-2018 to 31-May-2018

I am having an issue with scale_x_date. I am trying to scale my x axis from 1-Jun-2018 to 31-May-2018 by 1 month breaks. See example below. I am receiving several warnings (see below) and nothing plots. My Date column has been set as.Date.

ggplot(season.by.day, aes(x=Date, y=Total.attacks))+
geom_bar(stat="identity", color="black")+
theme_bw()+
theme_classic()+
scale_x_date(date_breaks="1 month", limits=c(as.Date("2018-06-01"), as.Date("2018-05-31")), labels = date_format("%d-%b"))+
scale_y_continuous(expand = c(0, 0))+
theme(axis.text=element_text(size=12,color="black"),axis.title=element_text(size=14, face="bold"))+
xlab("Day")+ylab("Number of shark attacks")

warning: 1: In min(x) : no non-missing arguments to min; returning Inf 2: In max(x) : no non-missing arguments to max; returning -Inf 3: In min(diff(sort(x))) : no non-missing arguments to min; returning Inf 4: Removed 365 rows containing missing values (position_stack).

Upvotes: 0

Views: 3279

Answers (1)

Ewa Krzyszczyk
Ewa Krzyszczyk

Reputation: 11

As I was not interested in the year, I forced my data to be Jun-2018 to May-2019 and ran the code again. It worked. But this would still be an issue for someone that is wanting it to be within the same year

Upvotes: 1

Related Questions