Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exercise 4_03b - scale_fill_manual bug #2

Open
aterhorst opened this issue Mar 22, 2023 · 1 comment
Open

Exercise 4_03b - scale_fill_manual bug #2

aterhorst opened this issue Mar 22, 2023 · 1 comment

Comments

@aterhorst
Copy link

Issue Overview

Unable to reproduce same result. Legend is not ordered as video.

Describe your environment

platform aarch64-apple-darwin20
arch aarch64
os darwin20
system aarch64, darwin20
status
major 4
minor 2.2
year 2022
month 10
day 31
svn rev 83211
language R
version.string R version 4.2.2 (2022-10-31)
nickname Innocent and Trusting

Steps to Reproduce

library(tidyverse)
library(sf)
library(janitor)
library(rmapshaper)
library(tigris)

most_popular_pets <- read_csv("data/pet-searches-by-state.csv") %>%
clean_names()

order_pet_popularity <- most_popular_pets %>%
count(pet, sort = TRUE) %>%
pull(pet)

us_contiguous <- states() %>%
clean_names() %>%
mutate(statefp = as.numeric(statefp)) %>%
filter(statefp < 60,
!statefp %in% c(2, 15)) %>%
ms_simplify()

us_most_popular_pets <- us_contiguous %>%
left_join(most_popular_pets,
by = c("name" = "state"))

colors_pets <-
list(
"Hamster" = "#AE76A6",
"Guinea pig" = "#92BFB1",
"Chinchilla" = "#694A38",
"Sugar glider" = "#A61C3C",
"Bearded dragon" = "#FFAD05"
)

colors_pets <- colors_pets[order_pet_popularity]

us_most_popular_pets <- us_most_popular_pets %>%
filter(!is.na(pet))

ggplot() +
geom_sf(data = us_most_popular_pets,
aes(fill = pet),
color = "white",
size = 0.2) +
scale_fill_manual(values = colors_pets,
name = "Most popular pet") +
theme_void()

Expected Behavior

I expect legend to be ordered by most popular pet as per video. Nope. I loaded 04_03e and got same result.

Current Behavior

colors_pets is ordered but scale_fill_manual is not displaying legend as per ordered colors

Possible Solution

Screenshots / Video

image

Related Issues

@andypicke
Copy link

Having same exact issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants