ipeadata-lab / ipeaplot

ipeaplot: criando graficos no padrão editorial do Ipea
https://ipeadata-lab.github.io/ipeaplot/
Other
2 stars 0 forks source link

scale_color_ipea() not working with continuous values #2

Closed rafapereirabr closed 1 year ago

rafapereirabr commented 1 year ago

reprex

library(templatesIpea)
library(ggplot2)

data("mtcars")

ggplot() +
  geom_point(data=mtcars, aes(x=mpg , y=cyl, color=cyl)) +
  templatesIpea::scale_color_ipea()

> Error: Continuous value supplied to discrete scale
PedroJorge7 commented 1 year ago

We have updated the package to support both continuous and discrete scales. Try the following code:

remotes::install_github("ipeadata-lab/ipea_templates")

library(templatesIpea)
library(ggplot2)
data("mtcars")

mtcars <- mtcars %>%
  mutate(carb = ifelse(carb == 1,"0-1",
                ifelse(carb == 2,"1-2",
                ifelse(carb == 3,"2-3",
                ifelse(carb == 4,"3-4",NA)))))

# continuous
ggplot() +
  geom_point(data=mtcars, aes(x=mpg , y=cyl, color=cyl)) +
  scale_color_continuous_ipea()

# discrete
ggplot(data=mtcars, aes(x=mpg , y=cyl, color=carb)) +
  geom_point() +
  scale_colour_discrete_ipea()