chris-prener / biscale

Bivariate Mapping with ggplot2
https://chris-prener.github.io/biscale/
GNU General Public License v3.0
121 stars 13 forks source link

Insufficient values in manual scale. 10 needed but only 9 provided. #14

Closed TimPrestby closed 4 years ago

TimPrestby commented 4 years ago

Before you open your issue:

Describe the bug I am trying to create a bivariate map of some data on the city census block group level. For 8 out of the 10 cities I am analyzing, I have had no issues. However, for certain fields for a particular city, I get the error as shown in the title.

Expected behavior Normally there is an output of a bivariate map with 9 classes. However, there is no output.

To Reproduce Please include a minimal reproducible example (AKA a reprex). If you've never heard of a reprex before, start by reading https://www.tidyverse.org/help/#reprex. When you create your reprex, please use a data set available in a package. mke.zip

# inset reprex here

library(sf)
library(ggplot2)
library(biscale)
library(cowplot)

d = read_sf('cities/mke.shp')

breaks = bi_class(d, x=cbg_o_medi, y=median_inc, style='equal', dim=3)

# create map
map <- ggplot() +
  geom_sf(data = breaks, mapping = aes(fill = bi_class), color = "#DEDEDE", size = 0.1, show.legend = FALSE)+
  bi_scale_fill(pal = "DkViolet", dim = 3) +
  labs(
    subtitle = "Distance and Income in Milwaukee at CBG Level"
  ) +
  bi_theme()
map

legend <- bi_legend(pal = "DkViolet",
                    dim = 3,
                    xlab = "Median Distance ",
                    ylab = "Median Income ",
                    size = 26)

# combine map with legend
finalPlot <- ggdraw() +
  draw_plot(map, 0, 0, 1, 1) +
  draw_plot(legend, 0.55, .65, 0.2, 0.2)

finalPlot

Screenshots If applicable, add screenshots to help explain your problem. bug

Desktop (please complete the following information):

Additional context Please unzip the file I attached and use the code I had to reproduce the problem. You can also see that if you change y=median_inc to y=entropy, there is no issue. It is strange. I double checked the columns for the data set and it seems 100% fine and is read in another GIS program.

chris-prener commented 4 years ago

hey @TimPrestby - thanks for reaching out, and great to hear the package is generally working for you! It looks like you've got some issues with your variable(s) that are causing problems with the classInt package, which is used to create the breaks for biscale. Did you have NA values in other variables as well? Unfortunately I can't reproduce this without some data.

TimPrestby commented 4 years ago

Chris, Thanks for the fast response. Yes! The package rocks. It is really helpful and has saved me a lot of time. The other variables that were working also had blank or null values. (Some of the census block groups didn't have data, so we included them in the geometry to show that they were there, but that there was no data attributed to them. I do wonder if this is the issue. However, it worked for many other datasets, and just this one and another were not working. I attached a zip file *now attached below) in the first message. I am not sure if this would allow you to reproduce it. Please let me know if I can be of further assistance.

mke.zip

TimPrestby commented 4 years ago

Chris, I figured out it was the NA values throwing it off. Thanks.

chris-prener commented 4 years ago

Thanks for letting me know @TimPrestby!