'How to delete label above bar chart in R that's already in the legend?
this is my first post!
Just wondering how to remove these titles above the charts:
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())
Solution 1:[1]
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())

Solution 2:[2]
I ended up changing the code at the very bottom! ADDED strip.text = element_blank())
Now the bar chart looks like this:
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())
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Kieran |
| Solution 2 | Nicholas Moore |

