How to change the axis tick values when using scale_fill_identity

I used this code to create values for color palette.

eg1 <- expand.grid( blue=seq(1, length.out=13, by=2), 
                    red=seq(1,70, by=10))
eg2 <- within(eg1, mix <- rgb(green=0, red=red, blue=blue, maxColorValue =70))

ggplot(eg2, aes(x=red, y=blue)) + geom_tile(aes(fill=mix), color="white") +
scale_fill_identity()

That gives me this:

I want to change the tick values on both axes. For the x axis, I want values from 1 to 7 and for the y axis, 1 to 13. I tried the following:


ggplot(eg2, aes(x=red, y=blue)) + geom_tile(aes(fill=mix), color="white") +
scale_fill_identity(breaks=c(10,20,30,40,50,60,70), labels=c(1,2,3,4,5,6,7)) 

ggplot(eg2, aes(x=red, y=blue)) + geom_tile(aes(fill=mix), color="white") +
scale_fill_identity(x=c(1,2,3,4,5,6,7))

ggplot(eg2, aes(x=red, y=blue)) + geom_tile(aes(fill=mix), color="white") +
scale_fill_identity(guide_axis(c(1,2,3,4,5,6,7)))

But none of them did what I was hoping. How can I change the tick values?

You can adjust the tick marks on the x axis with scale_x_continuous and y should be scale_y_continuous

eg1 <- expand.grid( blue=seq(1, length.out=13, by=2), 
                    red=seq(1,70, by=10))
eg2 <- within(eg1, mix <- rgb(green=0, red=red, blue=blue, maxColorValue =70))

library(ggplot2)
ggplot(eg2, aes(x=red, y=blue)) + geom_tile(aes(fill=mix), color="white") +
  scale_fill_identity() +
  scale_x_continuous(breaks=c(10,20,30,40,50,60,70), labels=c(1,2,3,4,5,6,7))

Created on 2022-11-02 with reprex v2.0.2

This topic was automatically closed 7 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.