DS4PS / cpp-529-spr-2020

Course shell for CPP 529 Data Practicum on Community Analytics for Spring 2020.
http://ds4ps.org/cpp-529-spr-2020
1 stars 1 forks source link

Lab 5 - Generating Dots #10

Open ecking opened 4 years ago

ecking commented 4 years ago

Hi there, I'm trying to run Part 3 of the lab and in the Rmd file I'm receiving an error at the first code chunk of the Generating Dots section. I have not modified any code.

Error in split.default(x = seq_len(nrow(x)), f = f, drop = drop, ...) : group length is 0 but data length > 0

AntJam-Howell commented 4 years ago

@ecking which code chunk are you referring to? The first code chunk is related to bringing in the ACS data. Are you referring to the first code chunk following the title Generating Dots that begins with acs_split? I've gone through that code chunk and do not find any error when I knit the lab or when I execute code line-by-line within the RMD file.

If the problem persists, please add the .RMD file you are using, specify the exact line of code you are having a problem with, and attach a screenshot where I can see the the last line of code you ran to produce the error and the error output.

ecking commented 4 years ago

Line 127, I can shoot you an email with the Rmd file.

image

AntJam-Howell commented 4 years ago

@ecking are you able to knit the file? On the .RMD file you sent I do not observe any error when knitting. The error is likely related to how you may be executing the code line-by-line. Try to highlight the entire code chunk at once to execute the code.

AntJam-Howell commented 4 years ago

@ecking It could also be related to how you may be running line-by-line executions in prior code chunks as well. Try executing entire code chunks at a time to make sure your ACS data is correct.

ecking commented 4 years ago

hmm when I go to knit, I get this message on the console. Same thing I get when I run all code chunks.

error

Niagara1000 commented 4 years ago

@ecking @Anthony-Howell-PhD Hi, I had the same error and I posted about it on the wrong discussion forum haha

After I knitted the file, I was able to see the fully knitted document, and I got no errors. I got errors only when I tried to run it inside the chunk itself. If I remember correctly, this was the code for creating a variable acs_split under the section "Generating Dots" in the Lab 5 Part 2 instructions documentation at https://ds4ps.org/cpp-529-spr-2020/LABS/Lab5b-MapVis2.html

I think the best solution might be to knit the entire file, maybe after restarting your computer and maybe even restarting RStudio.

AntJam-Howell commented 4 years ago

@ecking @Niagara1000 i'm sorry to see the troubles. I'm still unable to reproduce the error code that you are seeing on your end. I can knit without any error, and I can run the code line-by-line.

I've gone through and pasted a snippet of the code into an .R file up to the point of where you see the error. The link is here. Please open it as a new .R file (not .RMD), select the entire code and execute the code simultaneously in the .R file. Can you still produce the error or does it work?

ecking commented 4 years ago

Looks like restarting R and running worked. Glad I wasn't the only one with this error!

AntJam-Howell commented 4 years ago

@ecking Great. Sounds like it was an environment problem then. Glad you were able to fix the problem! @Niagara1000 good suggestion about restarting R and refreshing the R environment.

Niagara1000 commented 4 years ago

Hi,

I am looking at Question 3 from https://ds4ps.org/cpp-529-spr-2020/LABS/Lab5b-MapVis2.html and I'm not entirely sure of what Question 3 is asking for.

This is my Plot 6 code:

Plot6<-  ggplot(CenDF,aes(fill = pct_change)) +
  geom_sf(size = 0) +
  #geom_sf(data = major_roads_geo, color = "white", size = 0.8, fill = NA) +
  #geom_sf(data = minor_roads_geo, color = "white", size = 0.4, fill = NA) +
  **scale_fill_viridis**(option = "viridis", name = "% Change", limits = c(lower_limit, upper_limit), breaks = seq(lower_limit, upper_limit, 10)) +
  labs(title="Changes in House Price to Income Ratio",
       subtitle = "2017 5-Year Estimates vs. 2012 5-Year Estimates for Census Tracts",
       caption = paste0(
         "Data sources:",
         "\n  U.S. Census Bureau, 2012 and 2017 American Community Survey 5-Year Estimates"
       )
  ) +
  theme(plot.caption = element_text(hjust = 0, margin = margin(t = 15))) +
  theme(axis.ticks = element_blank(), axis.text = element_blank()) +
  theme(panel.background = element_blank())

Plot6

This code works. but the instructions say use 'scale_fill_manual' and when I did that, I got this error when I tried to knit the file:

Quitting from lines 343-412 (Lab5a-MapVis1.Rmd) 
Error in discrete_scale(aesthetic, "manual", pal, breaks = breaks, ...) : 
  unused argument (option = "viridis")
Calls: <Anonymous> ... withVisible -> eval -> eval -> scale_fill_manual -> manual_scale
In addition: Warning messages:
1: Removed 2 rows containing non-finite values (stat_bin). 
2: Removed 3 rows containing non-finite values (stat_bin). 
Execution halted

Can you please explain what is the difference between scale_fill_viridis and scale_fill_manual and when I need to use them?

AntJam-Howell commented 4 years ago

@Niagara1000 that is great you were able to manipulate the color scheme using scale_fill_viridis. There is nothing else you need to do in that case. The `scale_fill_manual' I suggest is only a hint in case you get stuck since in part 1 of the lab, most of the exercises use it, like the one below. Both operate quite similarly in that they are relied on to manipulate color schemes of the plot, although their implementation for making those changes differ. You can learn more about scale_fill_viridis here and scale_fill_manual

`## Convert Integer into factor variable CenDF$fill_factor <- quantcut(CenDF$HHInc_HousePrice_Ratio, q = seq(0, 1, by = .2)) CenDF$fill_factor = mapvalues(CenDF$fill_factor, from = levels(CenDF$fill_factor), to = c("1","2","3", "4","5"))

Assign 5 colors

col.ramp <- viridis(n = 5) # number of groups you desire Plot4<-ggplot(CenDF) + geom_sf(aes(fill = fill_factor), color=NA) + coord_sf(datum=NA) + labs(title = "House-Price-to-Income Ratio", caption = "Source: ACS 5-year, 2013-2017", fill = "Price-Income Ratio") + scale_fill_manual("Price-Income Ratio \n (Quintiles)",values = col.ramp) Plot4`

Niagara1000 commented 4 years ago

ok, thank you Professor