DS4PS / ddmp-uw-class-spring-2019

Data-Driven Management & Policy Course at UW, Spring 2019
https://ds4ps.github.io/ddmp-uw-class-spring-2019/
4 stars 3 forks source link

Lab 7 Errors #12

Open pearsonkm opened 5 years ago

pearsonkm commented 5 years ago

Hi all, I have a few errors related to Lab 7. The package tmap doesn't seem to be loading.

Screen Shot 2019-05-19 at 6 37 47 PM

Second, the second visualization isn't loading because the object 'count_year' cannot be found. Am I supposed to define count_year?

Screen Shot 2019-05-19 at 6 38 02 PM

ejvanholm commented 5 years ago

To your first question, have you installed tmap in the past?

ejvanholm commented 5 years ago

count_year should be getting created in the line with count(), so I'm not sure why that is an issue. if you create that variable earlier after creating Year does the code work?

lecy commented 5 years ago

You might try replacing the + with pipes:

https://community.rstudio.com/t/why-cant-ggplot2-use/4372/

It is sometimes easier to create your dataset first because some of the geoms don't play well with pipes.

pet_species <-
pet %>%
group_by( Species ) %>%
count( Year, name="count_year" )

ggplot( data=pet_species, ... )
pearsonkm commented 5 years ago

@ejvanholm I installed tmap before running that line of code

Now, R is saying it is having trouble finding "Species"

Screen Shot 2019-05-29 at 2 58 19 PM

pearsonkm commented 5 years ago

@lecy Thanks, I will try that if it seems to be an issue!

ejvanholm commented 5 years ago

That's one of the bigger complications with Markdown documents that I've always struggle to explain. When you're writing a Markdown, the working direction defaults to the file that the document is saved in. So you don't need to set your working directory if the data you're uploading is in the same folder that your Markdown is being written in to, but setwd() doesn't work. That's the easy solution.

Even though the folder that the document is saved in becomes your working directory, you can grab data from other folders. To move down a folder, you need to use a slash, and to move up a level you use two dots "..".

So for example, if I have three folders, let's say "Class", "Labs", "Lab 7", and I have my document saved in Labs I can move up to Class or down to Lab 7. read.csv("Lab 7/Data.csv")

read.csv("../Data.csv").

It definitely isn't my favorite feature of Markdown

pearsonkm commented 5 years ago

@ejvanholm Ah, thank you! Okay, I worked it out.

Now, the column Species is unknown. Any ideas as to why that is?

Screen Shot 2019-05-29 at 4 17 09 PM

ejvanholm commented 5 years ago

If the data i loading I don't know why that would be an issue. The group_by() was initially done prior to count(), which might make the difference. If that doesn't work, check the names in the data set to make sure that everything is loading correctly.

pearsonkm commented 5 years ago

I think now str_sub is the issue - R cannot find the function.

All the data set names are correct. Species matches Species.

pearsonkm commented 5 years ago

Do I have to change the License.Issue.Date column to just include years?

ejvanholm commented 5 years ago

If the issue is with str_sub, you need to make sure that the package stringr is loaded on your computer and active. Make sure you've run install.packages("stringr") and that library"stringr) is in the Markdown document.

The reason for that line of code is to change the dates from daily to annual figures. You can run the code with the daily data and see how the plot looks to you. Making a good, intelligible plot is what matters most.

pearsonkm commented 5 years ago

@ejvanholm I have both of this commands installed. str_sub might be working now, but again I am having trouble with count(). I will email you my .Rmd if that's alright?