Giter Site home page Giter Site logo

Comments (2)

wilkox avatar wilkox commented on August 10, 2024

Hi Zach,

The issue here is that you are (correctly) using the fill aesthetic, but trying to modify it with scale_colour_*() functions instead of scale_fill_*() functions. For the first example, if you use scale_fill_gradient2() it should work as expected:

ggplot(example_genes, aes(xmin = start, xmax = end, y = molecule, fill = start)) +
  geom_gene_arrow() +
  facet_wrap(~ molecule, scales = "free", ncol = 1) +
  scale_fill_gradient2()

Created on 2021-12-15 by the reprex package (v2.0.1.9000)

For the second example, if you just change scale_colour_brewer() to scale_fill_brewer(), you'll get an error because the Brewer scales (as implemented in ggplot2) are designed for discrete variables:

ggplot(example_genes, aes(xmin = start, xmax = end, y = molecule, fill = start)) +
  geom_gene_arrow() +
  facet_wrap(~ molecule, scales = "free", ncol = 1) +
  scale_fill_brewer(palette = "Greens")
#> Error: Continuous value supplied to discrete scale

Created on 2021-12-15 by the reprex package (v2.0.1.9000)

Instead you can use the scale_*_distiller() functions which will interpolate the Brewer palettes for continuous variables:

ggplot(example_genes, aes(xmin = start, xmax = end, y = molecule, fill = start)) +
  geom_gene_arrow() +
  facet_wrap(~ molecule, scales = "free", ncol = 1) +
  scale_fill_distiller(palette = "Greens")

Created on 2021-12-15 by the reprex package (v2.0.1.9000)

from gggenes.

zreitz avatar zreitz commented on August 10, 2024

Oh of course! Thank you the quick reply!

from gggenes.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.