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

Error Knitting document #7

Open
theadizz opened this issue May 5, 2019 · 1 comment
Open

Error Knitting document #7

theadizz opened this issue May 5, 2019 · 1 comment

Comments

@theadizz
Copy link

theadizz commented May 5, 2019

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:

  • nominal columns include: ID, SEX, and Race while LOCUS, CONCPT, AND MOT coums take on an ordinal or numerical charater.
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:

  • The ordinal varible I selected for part 3 is LOCUS or locus of control.
baseOrd2 = ggplot(lab5, aes(y=as.numeric(LOCUS))) 
baseOrdBox = baseOrd2 + geom_boxplot() 

baseOrdBox
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
Copy link
Collaborator

One of your code chunks has the name:
freqTab_abs

change it...try: freqTab_abs2

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