0

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())
r2evans
  • 141,215
  • 6
  • 77
  • 149
  • 1
    Your `col=` and `fill=` mean that the bar outlines will be based on `Cell_lines` and the (much more visible) bar contents will be based on `Variant_Classification`. Are you saying you cannot see the colored borders on the bars or that they are clearly the same color? It's difficult to tell without making this reproducible. – r2evans Sep 21 '22 at 18:39
  • The plot for example has 6 columns 2 red, 2 blue, 2 purple, one red outlined with green and one red outlined with yellow, one blue outlined with green and one blue outlined with yellow, etc... its not clear like that so I want to make it one red and one red but shaded with black, one blue and one blue shaded with black etc..... in case if you have different idea, its good also. Thanks –  Sep 21 '22 at 18:54
  • 1
    I can't really do much with that, please provide [sample data](https://stackoverflow.com/q/5963269) – r2evans Sep 21 '22 at 19:09

1 Answers1

0

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"))
Shawn Hemelstrand
  • 2,676
  • 4
  • 17
  • 30