firmo23
firmo23

Reputation: 8404

Removing background color removes axes lines as well

I have the dataframe below

Target_Category<-c("Adhesion","Cytochrome")
Validated<-c(5,10)
Candidate<-c(7,8)
dataf<-data.frame(Target_Category,Validated,Candidate)

And I create a stacked bar plot with

dataf %>%
  gather(col, value, -Target_Category) %>%
  ggplot() + 
  geom_bar(aes(Target_Category, value, fill = col), stat="identity")+
  theme(panel.background = element_blank())

The issue is that when I try to remove the background color with

theme(panel.background = element_blank()) 

the x and y axes are disappeared as well.

Upvotes: 1

Views: 109

Answers (1)

mnm
mnm

Reputation: 2012

Try the following

library(tidyverse)    
dataf %>%
  gather(col, value, -Target_Category) %>%
  ggplot() + 
  geom_bar(aes(Target_Category, value, fill = as.factor(col)), stat="identity")+
  theme_classic()

The trick is coercing col to factor. By the way in your question, the dataf has no column called col

Upvotes: 1

Related Questions