Koko Mutai
Koko Mutai

Reputation: 27

Separating colors in ggplot to avoid fuzzyness

enter image description here

Here is a picture I generated using ggplot2 and the command I used is:

ggplot(dat3.prop1DF, aes(x=X1, y=value, fill=X2)) + 
  geom_bar(stat="identity") + 
  scale_fill_manual(values=scales::hue_pal(h = c(0,360) + 15, c=100, l=65, 
                    h.start=0, direction=1)(length(levels(dat3.prop1DF$X2)))) + 
  theme(axis.text.x=element_text(angle=90, hjust=0))

Unfortunately, I can't see some of the Taxon and my colors on the geom_bar are fuzzy. Can someone help me get clearcut colors and also ensure that l can see all my Taxa.

Thanks.

Upvotes: 0

Views: 102

Answers (1)

Jaap
Jaap

Reputation: 83265

As @Roland said, you are trying to put too much info into one plot. In your case using faceted plots might be a wise route to go. If I understand your plot correctly, you want to compare between the different X1 values and also between the different X2 value (bacteria?). Below you'll find two pieces of example code. Try them and see what suits you best.

Creating a faceted plot for each type of bacteria:

# example 1
ggplot(dat3.prop1DF, aes(x=X1, y=value, fill=X2)) + 
  geom_bar(stat="identity") + 
  theme(axis.text.x=element_text(angle=90, hjust=0)) +
  facet_wrap(~ X2)

Creating a faceted plot for each type of X1 value (whatever that may be):

# example 2
ggplot(dat3.prop1DF, aes(x=X2, y=value, fill=X1)) + 
  geom_bar(stat="identity") + 
  theme(axis.text.x=element_text(angle=90, hjust=0)) +
  facet_wrap(~ X1)

Upvotes: 1

Related Questions