Home > Net >  How to delete label above bar chart in R that's already in the legend?
How to delete label above bar chart in R that's already in the legend?

Time:05-07

this is my first post!

Just wondering how to remove these titles above the charts:

enter image description here

Here's the code for the diagram!

I imagine I'll have to use something like:
p theme(axis.title.x = element_blank(), axis.title.y = element_blank())

ggplot(data=bike_data_v4) 
      geom_bar(mapping = aes(x=day_of_week,fill=member_casual)) 
      scale_x_discrete(limits = c("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"),
                       labels = c("Sun","Mon","Tue","Wed","Thu","Fri","Sat"))  #the discrete lines show how I rearranges the x-axis labels to go from sun-sat and be renamed to shorter text
      facet_wrap(~member_casual) 
      labs(title="Weekly Rider Differences by Cyclist Type", subtitle="Members vs. Casual Riders",
           x = "Day of the Week",
           y = "Number of Overall Rides",
           caption="Data Provided by Google Capstone Project") 
      scale_y_continuous(limits=c(0,500000), labels = scales::comma)  #this combined scale_y_continuous(limits=c(0,500000)  AND scale_y_continuous(labels=comma)
      theme_fivethirtyeight() 
      labs(fill='Rider Type') 
      theme(axis.title = element_text())


  

CodePudding user response:

You are looking for the strip.text option.

library(tidyverse)
iris |> 
  ggplot(aes(x = Sepal.Length, y = Petal.Length))   
  geom_point()   
  facet_wrap(~ Species)   
  theme(strip.text = element_blank())

CodePudding user response:

I ended up changing the code at the very bottom! ADDED strip.text = element_blank())

Now the bar chart looks like this:enter image description here

ggplot(data=bike_data_v4) 
  geom_bar(mapping = aes(x=day_of_week,fill=member_casual)) 
  scale_x_discrete(limits = c("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"),
                   labels = c("Sun","Mon","Tue","Wed","Thu","Fri","Sat"))  #the discrete lines show how I rearranges the x-axis labels to go from sun-sat and be renamed to shorter text
  facet_wrap(~member_casual)  
  theme(strip.text = element_blank()) 
  labs(title="Weekly Rider Differences by Cyclist Type", subtitle="Members vs. Casual Riders",
       x = "Day of the Week",
       y = "Number of Overall Rides",
       caption="Data Provided by Google Capstone Project") 
  scale_y_continuous(limits=c(0,500000), labels = scales::comma)  #this combined scale_y_continuous(limits=c(0,500000)  AND scale_y_continuous(labels=comma)
  theme_fivethirtyeight(base_size = 12, base_family = "sans") 
  labs(fill='Rider Type') 
  theme(axis.title = element_text(), strip.text = element_blank())
  • Related