I have a data set like this
df <- data.frame(ID=c("10","11","14","15","16","18","3","5","6","8","9","n"),
A=c("C","U","U","C","C","C","U","C","U","U","C","U"),
B=c("P","P","C","P","C","C","C","P","C","P","C","P"),
N=c(7,2,8,6,2,3,7,4,9,5,4,4))
ID is the identification number of each row. N is the value. A and B are two categories. I would like to create a bar plot or similar to compare N based on A and B category.
Here is my code:
ggplot(data=df,aes(x=ID,y=N,fill=A)) +
geom_col(position="dodge")+
facet_wrap(~B)
Here I hope I can put the same color together in each "C" and "P" category, and I would like to delete the empty columns from the graph, for example ID-10 in "C" cateogory.
I probably did not use the most appropriate way to make this figure, but this is what I can think of right now. If you have better ways to create the figure, could you help me please? Thank you!