Changing the Y-scale using coord_polar

Viewed 127

Hi so Im brand new to coding and Ive been following along a youtube tutorial on how to make a circular barplot graph in RStudio. The issue is Im using data that goes up to the tens of millions and would like to zoom in on the y-scale to have a more detailed look a the data. Ive tried using coord_cartesian and setting the ylim but nothing changes and get the message "coordinate system already present"

How can I change the y-scale to be between 40,000,000 and 70,000,000?

This is what I have


#create data
month <- c('Mar 19', 'Apr 19', 'May 19', 'June 19', 'Jul 19', 'Aug 19', 'Sept 19','Oct 19', 'Nov 19', 'Dec 19', 'Jan 20', 'Feb 20')
rides <- c(67583312, 59590909,  68449486,   60163410,   63675286,   66059525,   63148128,   66208467,   65481522,   58539077,   57098170,   60289465)


df=data.frame(month,rides)
df



ggplot(df,aes(x=month,y=rides, fill=month))+
    geom_bar(stat='identity')+
    theme(legend.position = "none")+
    coord_cartesian(ylim(40000000, 70000000), clip = "on")+
    coord_polar(start=0)
 
 
1 Answers

One workaround would be to change the values of the y-variable for the purposes of the plot and then manually adjust the labels of the y-axis.

ggplot(df,aes(x=month, y=rides -40000000, fill=month))+
  geom_bar(stat='identity')+
  theme(legend.position = "none")+
  coord_polar(start = 0) +
  scale_y_continuous(labels = c(40000000, 50000000, 60000000, 70000000))

Output: enter image description here

I am not sure whether this is a good approach, though. Intuitively, one would probably expect the centre to be 0, rather than 40,000,000. But hopefully someone else can post a clean solution.

Related