ggplot color problem

Hi all,

I am trying to do a plot with ggplot(). When I am doing the code I add the limits to my chunk, and the color of my plot disappears, and it becomes a scatter plot in black and white. Can someone help me, please?

The code chunk is:

ggplot(data = one.data) +
  geom_point(aes(plot_X, plot_Y, colour = value, size = log_size), alpha = I(0.7)) +
  scale_color_gradientn(colors = c("blue", "green", "yellow", "red"),limits = c( min(one.data$value), 0))`

Without limits function the color works. However, with the limit() function it doesn't work and becomes black and white. And I need these limits to create my plot.

Thank you
Felix

Your quote marks are unbalanced, the issues occurs where you write yellow.

1 Like

imposing limits effects the way colours are applied, you may have found a way to set the limits just so that the full range of colours is not expressed. I don't feel able to comment on that without access to your data or something analogous

Here is an attempt at that with the built-in iris dataset used as example data. I set the limits to the range covering the min and the media, and you can see how half the dots are coloured and half are not. You didn't say what it was you hoped to achieve by setting limits, perhaps there is a different way to do what you intend that doesnt effect the colouring, only you are setting limits on the colouring function, so it appears that you do want to influence the colours ... Can you clarify this point ?

library(tidyverse)

ggplot(data = iris) +
  geom_point(aes(Sepal.Length, Sepal.Width,
    colour = Petal.Length,
    size = Petal.Width
  ),  alpha = I(0.7)
  ) +
  scale_color_gradientn(
    colors =
      c("blue", "green", "yellow", "red"),
    limits = c(
      min(iris$Petal.Length),
      median(iris$Petal.Length)
    )
  )

2 Likes

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.