scale_alpha_continuous - ggplot2

Hello all,

I am trying to make a grouped bar chart in which the bars are colored based on one variable(binary/ e.g. Group 1 and group2), and then the transparency of the bars are based on another value(continuous/ e.g. p-value). I am able to get very close using scale_fill_brewer and scale_alpha. The issue that I am running into is that with scale_alpha i get a legend that is cut into categories, and I would really rather t be a continuous scale like that generated by scale_fill_gradient. I have searched and searched but cannot figure out if this is possible. Any insight would be very helpful. Thank you all.

ggplot(bardat, aes(x=reorder(KEGG_PATHWAY_description, -pvals), y=value)) +
  geom_bar(stat="identity", aes(fill=variable, alpha = pvals), position="dodge") +
  ylim(0, max(bardat$value) + 0.6) + xlab("") +
  coord_flip() +
  scale_fill_brewer(palette = "Set1",
                    name="",
                    breaks=c("fold_enrichment_list1", "fold_enrichment_list2"),
                    labels=c("Fold Enrichment in \nlist 1\n", "Fold enrichment in \nlist 2\n")) +
  scale_alpha(trans = 'log10') +
  geom_text(data=subset(df.ss, variable %in% c("diff_enrich_adjusted")),
            aes(x = KEGG_PATHWAY_description, y = (max(bardat$value) + 0.3), label = round(value, 4))) +
  labs(alpha = "List specific p-value") 

Attempt # 2 gets close as well, but not quite. This gets me the continuous gradient, and groups the bars on the plot, but does not have different gradients for the different variables (e.g. fold_enrichment1 should go from light blue to dark blue, and fold_enrichment_2 should go from light red to dark red)

ggplot(bardat, aes(x=reorder(KEGG_PATHWAY_description, -pvals), y=value)) +
  geom_bar(stat="identity", aes(col=variable, group=variable, fill=pvals), position="dodge") +
  ylim(0, max(bardat$value) + 0.6) + xlab("") +
  coord_flip() +
  scale_fill_brewer(palette = "Set1",
                    name="",
                    breaks=c("fold_enrichment_list1", "fold_enrichment_list2"),
                    labels=c("Fold Enrichment in \nlist 1\n", "Fold enrichment in \nlist 2\n")) +
  scale_fill_continuous(trans = 'log10') +
  geom_text(data=subset(df.ss, variable %in% c("diff_enrich_adjusted")),
            aes(x = KEGG_PATHWAY_description, y = (max(bardat$value) + 0.3), label = round(value, 4))) +
  labs(alpha = "List specific p-value") 

See this link for hacked version courtesy of teunbrand.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.