0
votes

My barplot has NA in x-axis therefore it returns some weird image of my data x-axis should be months like "Jan Feb Mar .... DEC"

ggplot(x, aes(x = Month, y = x$freq)) + geom_bar(aes(fill=x$Sex), stat = 'identity')

Here is the resulting plot

enter image description here

1
not sure but you dont need to keep using x$rawr
please provide minimal dataframe to reproduce your problem and therefore be able to help.OFish

1 Answers

0
votes

Try the following code:

# Sample dataframe
df <- data.frame(sex=c("Female","Female", "Male","Male"), month=c("Jan","Feb","Jan","Feb"), freq=c(130,160,160,175))
# Reorder the factor levels of a month column
df$month <- factor(df$month, levels = c("Jan","Feb"))
# ggplot
library('ggplot2')
ggplot(df, aes(x=month, y=freq, fill=sex)) + geom_bar(position="dodge", stat="identity")

enter image description here