Home > Net >  How to shade columns from dataframe on ggplot graph that has two dataframes on R?
How to shade columns from dataframe on ggplot graph that has two dataframes on R?

Time:09-27

How to shade columns from dataframe on ggplot graph that has two dataframes on R?

I merged two dataframes together and performed ggplot on R, which has values of two dataframes, the problem is that both dataframes columns values has same color, for example one column on plot has bue color for both dataframes but one is determined with red outline and one with green outline, this makes the graph not very clear to look at, how to make one column shaded one not shaded for all columns for the dataframes on the graph?

df$Cell_lines = 'cell_one'
data2$Cell_lines = 'cell_two'
df3=rbind(df,data2)

ggplot(df3, aes(x=Variant_Classification, y=Number_of_Genes, col =Cell_lines, fill = Variant_Classification))   
  geom_bar(stat="identity",position = 'dodge')   
  theme_minimal()   labs(title ="cell_one vs cell_two")  
  theme(
    axis.title.x=element_blank(), axis.text.x=element_blank(), 
    axis.ticks.x=element_blank())

CodePudding user response:

The answer is:

df3=rbind(df,data2) ggplot(df3, aes(x=Variant_Classification, y=Number_of_Genes,col =Cell_lines,fill = Variant_Classification)) geom_bar(stat="identity",position='dodge',size =1) theme_minimal() labs(title="cell_twovscell_one") theme(axis.title.x=element_blank(),axis.text.x=element_blank(),axis.ticks.x=element_blank()) scale_color_manual(values = c("cell_one" = "red","cell_two"="black"))

  • Related