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

Error Knitting document #7

Open theadizz opened 5 years ago

theadizz commented 5 years ago

I have completed the document, yet in attempt to knit:

processing file: session5_LAB.Rmd Error in parse_block(g[-1], g[1], params.src) : duplicate label 'freqTab_abs' Calls: ... process_file -> split_file -> lapply -> FUN -> parse_block Execution halted

pops up. May you help trouble shoot?

Session 5 LAB: Intro to Visualization

by Adrienne Hampton

Part 1:

library("rio")
setwd("~/Desktop/session5")
lab5 <- import("~/Desktop/session5/hsb.sav")
lab5
str(lab5,width = 70,strict.width='cut')

Part 2: Make two barplots for one nominal variable (2 bar plots, both should have a title and a source)

library("rio")
lab5$RACE=factor(lab5$RACE,
                        levels=c(1,2,3,4),
                        labels=c("Hispanic","Asian","Black","White"),
                        ordered = T)

table(lab5$RACE,exclude = 'nothing')
library(ggplot2)
frTable=as.data.frame(table(lab5$RACE))
names(frTable)=c('Type','Count')

baseNom= ggplot(data = frTable, 
             aes(x=Type, y=Count)) 

titleText='High School and Beyond Data Set'
sourceText='Source: National Opinion Research Center (1980)'
xaxisText= 'Race or ethnicity'
yaxisText= 'Count' 

baseNom= baseNom + geom_bar(stat = 'identity')

baseNom2 =  baseNom + labs(title=titleText,
                               x = xaxisText, 
                               y = yaxisText,
                               caption = sourceText)

baseNom2

The second plot should include more customized changes of your choice.

library(ggplot2)
frTable=as.data.frame(table(lab5$RACE))
names(frTable)=c('Type','Count')

baseNom= ggplot(data = frTable, 
             aes(x=Type, y=Count)) 

titleText='High School and Beyond Data Set'
sourceText='Source: National Opinion Research Center (1980)'
xaxisText= 'Race or ethnicity'
yaxisText= 'Count' 

baseNom= baseNom + geom_bar(stat = 'identity')

baseNom2 =  baseNom + labs(title=titleText,
                               x = xaxisText, 
                               y = yaxisText,
                               caption = sourceText)

baseNom2

baseNom2 + geom_bar(stat = 'identity',
                   colour='white', # border
                   fill='pink') 

Part 3:

baseOrdBox


```{r freqTab_abs, eval=TRUE}
baseOrd2 = ggplot(lab5, aes(y=as.numeric(LOCUS))) 
lab5_LOCUS=lab5[complete.cases(lab5$LOCUS),]

baseOrd2 + geom_boxplot(colour='PURPLE',fill='WHITE') 

Part 4:

length(unique(lab5$LOCUS))
summary(lab5$LOCUS)

titleText='High School and Beyond Data Set'
sourceText='Source: National Opinion Research Center (1980)'
xaxisText= 'locus'
yaxisText= 'Count' 

baseIntHist= baseIntHist + labs(title=titleText,
                               x = xaxisText, 
                               y = yaxisText,
                               caption = sourceText)

baseIntHist

lab5_LOCUS=lab5[complete.cases(lab5$LOCUS),]

baseInt2= ggplot(lab5_LOCUS,aes(x = LOCUS))  
baseIntHist= baseInt2 + geom_histogram()
baseIntHist
lab5_LOCUS=lab5[complete.cases(lab5$LOCUS),]

baseInt2= ggplot(lab5_LOCUS,aes(x = LOCUS))  
baseIntHist= baseInt2 + geom_histogram()
baseIntHist

titleText='High School and Beyond Data Set'
sourceText='Source: National Opinion Research Center (1980)'
xaxisText= 'locus'
yaxisText= 'Count' 

baseIntHist= baseIntHist + labs(title=titleText,
                               x = xaxisText, 
                               y = yaxisText,
                               caption = sourceText)
baseIntHist

baseIntHist2= baseIntHist + theme(plot.caption = element_text(hjust = 0), 
                                   plot.title = element_text(hjust = 0.5))

baseIntHist2

baseIntHist2 + geom_histogram(bins=7,
                          colour='magenta',
                          fill='purple')

Part 5:

library(ggplot2)
frTable=as.data.frame(table(lab5$RACE))
names(frTable)=c('Type','Count')

baseNom= ggplot(data = frTable, 
             aes(x=Type, y=Count)) 

titleText='High School and Beyond Data Set'
sourceText='Source: National Opinion Research Center (1980)'
xaxisText= 'Race or ethnicity'
yaxisText= 'Count' 

baseNom =  baseNom + labs(title=titleText,
                               x = xaxisText, 
                               y = yaxisText,
                               caption = sourceText)

baseNom

baseNom2= baseNom + geom_point() 
baseNom2

Part 6 (For final project):


library("rio")
setwd("~/Desktop/session5")
bike <- import("~/Desktop/session5/jump bike data.xlsx")
bike

table(bike$Distance,exclude = 'nothing')
library(ggplot2)
frTable=as.data.frame(table(bike$Distance))
names(frTable)=c('Type','Count')

baseNom= ggplot(data = frTable, 
             aes(x=Type, y=Count)) 

titleText='Biking Data'
sourceText='Source: National Opinion Research Center (1980)'
xaxisText= 'Race or ethnicity'
yaxisText= 'Count' 

baseInt2= ggplot(bike_DISTANCE,aes(x = Distance))  
baseIntHist= baseInt2 + geom_histogram()
baseIntHist

baseOrd2 = ggplot(bike, aes(y=as.numeric(Distance))) 
baseOrdBox = baseOrd2 + geom_boxplot() 

baseOrdBox
MAGALLANESJoseManuel commented 5 years ago

One of your code chunks has the name: freqTab_abs

change it...try: freqTab_abs2