简体   繁体   中英

Changing x and y labels on a bar plot

I'm looking to figure out how to change the x-labels that show the default M and F variables from the data frame to become "Male" and "Female" instead. I tried looking online, but I still couldn't seem to find the best approach for this.

This is my code

# Create a visualization between males and female subjects
ggplot(data=subjectID,aes(x=Sex,fill=Sex))+geom_bar(col="black") + 
  xlab("Sex") + ylab("Count") + ggtitle("Count Between Males and Females")

This gets me to generate a graph that looks like this below. Any help on changing this would be appreciated thank you!

在此处输入图片说明

The issue here is not with the graph label names. The M and F are the two unique values in your column Sex of subjectID data frame, which are being plotted. Instead of changing the x and y labels, you need to replace the M and F to Male and Female respectively in your Sex column of subjectID dataframe.

This code might help you fix the issue. subjectID[subjectID=="M"]<-'Male' subjectID[subjectID=="F"]<-'Female'

Run these two lines before plotting the graph

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM