Presentation is loading. Please wait.

Presentation is loading. Please wait.

Plotting risk perceptions vs. political orientation & science comprehension Steve Genco August 19, 2015.

Similar presentations


Presentation on theme: "Plotting risk perceptions vs. political orientation & science comprehension Steve Genco August 19, 2015."— Presentation transcript:

1 Plotting risk perceptions vs. political orientation & science comprehension Steve Genco August 19, 2015

2 R code Define variables ## load dataset load("C:/Users/User/Dropbox/R code/kahan/kahan.risk.RData") #set variables libcon <- Kahan.risk$id..Zconservrepub gwrisk <- Kahan.risk$GWRISK nukerisk <- Kahan.risk$NUKERISK scicomp <- Kahan.risk$scicomp_i ## jitter variables ## set randomizing seed so jitters always produce same points set.seed(1) jlibcon <- jitter(libcon) jjlibcon <- jitter(libcon, amount=0.5) jjscicomp <- jitter(scicomp, amount=0.5) jgwrisk <- jitter(gwrisk) jnukerisk <- jitter(nukerisk) ## fit regression lines gwfit <- lm(gwrisk ~ libcon) nukefit <- lm(nukerisk ~ libcon) gwfit.sci <- lm(gwrisk ~ scicomp) nukefit.sci <- lm(nukerisk ~ scicomp) ## cut libcon into 8 bins from -2 to 2 by 0.5 libconbin <- cut(libcon, breaks=seq(-2,2,by=0.5)) table (libconbin, gwrisk) table (libconbin,nukerisk) ## cut scicomp into 10 bins from -2.5 to 2,5 by 0.5 scicompbin <- cut(scicomp,breaks=seq(-2.5,2.5,by=0.5)) table (scicompbin, gwrisk) table (scicompbin, nukerisk) ## set palette to semi-transparent rainbow palette(adjustcolor(rainbow(8), alpha=0.5))

3 R code gwrisk by libcon ## libcon by gwrisk ## pch = point char ## bty = "l" = show left and bottom axes ## col = color assignment, add 1 to indicator var because rainbow(0) is white ## change col to "white" to create blank frame for symbols only plot ## yaxt = 'n' = turn off y-axis (add later with symbol overlay) plot(jjlibcon, jgwrisk, pch=20, bty="l", col = gwrisk+1, yaxt = 'n', main="Liberal-Conservative by Global Warming Risk") ## axis puts ticks at 0 thru 7 axis(side = 2, at = seq(0,7)) #abline(gwfit, lwd=2, col="blue") ## create data.frame for bubbles -- libcon, gwrisk size <- table (gwrisk, libconbin) ## flatten the table into a vector circle.size <- c(size) ## create x-axis points in middle of each bin libcon.pts <- seq(-1.75,1.75,by=0.5) ## create x-var for symbol placement data.frame x.libcon <- rep(libcon.pts, c(8,8,8,8,8,8,8,8)) ## create y-axis points for each level of y-var gwrisk.pts <- seq(0,7) ## create y-var for symbol placement data.frame y.risk <- rep(gwrisk.pts,8) ## create new data.frame for overlaying labels on current plot circles.libcon.gw <- data.frame(x.libcon, y.risk+1, circle.size) ## overlay circles on current jitter plot ## circle.size sizes circles relative to N at that (x,y) point ## inches controls scale of circles, default is inches=1 ## fg = foreground color (line) for circles ## bg = background color (fill) for circles, assign based on y.risk+1 ## add=TRUE overlays symbols on current plot, set to FALSE or remove for new plot symbols(x.libcon, y.risk, circle=circle.size, inches=0.5, fg="white", bg=y.risk+1, add=TRUE) ## add the fit line abline(gwfit, lwd=2, col="blue")

4 Jitter plot gwrisk by libcon

5 Bubble plot gwrisk by libcon

6 Combined jitter-bubble plot gwrisk by libcon

7 R code nukerisk by libcon ## libcon by nukerisk plot(jjlibcon, jnukerisk, pch=20, bty="l", col = nukerisk+1, yaxt = 'n', main="Liberal-Conservative by Nuclear Power Risk") ## axis puts ticks at 0 thru 7 axis(side = 2, at = seq(0,7)) #abline(nukefit, lwd=2, col="blue") ## create data.frame for bubbles -- libcon, nukerisk size <- table (nukerisk, libconbin) circle.size <- c(size) libcon.pts <- seq(-1.75,1.75,by=0.5) x.libcon <- rep(libcon.pts, c(8,8,8,8,8,8,8,8)) nukerisk.pts <- seq(0,7) y.risk <- rep(nukerisk.pts,8) circles.libcon.nuke <- data.frame(x.libcon, y.risk, circle.size) #overlay circles on current jitter plot symbols(x.libcon, y.risk, circle=circle.size, inches=0.5, fg="white", bg=y.risk+1, add=TRUE) abline(nukefit, lwd=2, col="blue")

8 Jitter plot nukerisk by libcon

9 Bubble plot nukerisk by libcon

10 Combined jitter-bubble plot nukerisk by libcon

11 R code gwrisk by scicomp ## scicomp by gwrisk plot(jjscicomp, jgwrisk, pch=20, bty="l", col = gwrisk+1, yaxt = 'n', main="Science Comprehension by Global Warming Risk") ## axis puts ticks at 0 thru 7 axis(side = 2, at = seq(0,7)) #abline(gwfit.sci, lwd=2, col="blue") ## create data.frame for bubbles -- scicomp, gwrisk size <- table (gwrisk, scicompbin) circle.size <- c(size) scicomp.pts <- seq(-2.25,2.25,by=0.5) x.scicomp <- rep(scicomp.pts, c(8,8,8,8,8,8,8,8,8,8)) gwrisk.pts <- seq(0,7) y.risk <- rep(gwrisk.pts,10) circles.scicomp.gw <- data.frame(x.scicomp, y.risk, circle.size) #overlay circles on current jitter plot symbols(x.scicomp, y.risk, circle=circle.size, inches=0.5, fg="white", bg=y.risk+1, add=TRUE) abline(gwfit.sci, lwd=2, col="blue")

12 Jitter plot gwrisk by scicomp

13 Bubble plot gwrisk by scicomp

14 Combined jitter-bubble plot gwrisk by scicomp

15 R code nukerisk by scicomp ## scicomp by nukerisk plot(jjscicomp, jnukerisk, pch=20, bty="l", col = nukerisk+1, yaxt = 'n', main="Science Comprehension by Nuclear Power Risk") ## axis puts ticks at 0 thru 7 axis(side = 2, at = seq(0,7)) #abline(nukefit.sci, lwd=2, col="blue") ## create data.frame for bubbles -- scicomp, nukerisk size <- table (nukerisk, scicompbin) circle.size <- c(size) scicomp.pts <- seq(-2.25,2.25,by=0.5) x.scicomp <- rep(scicomp.pts, c(8,8,8,8,8,8,8,8,8,8)) nukerisk.pts <- seq(0,7) y.risk <- rep(nukerisk.pts,10) circles.scicomp.nuke <- data.frame(x.scicomp, y.risk, circle.size) #overlay circles on current jitter plot symbols(x.scicomp, y.risk, circle=circle.size, inches=0.5, fg="white", bg=y.risk+1, add=TRUE) abline(nukefit.sci, lwd=2, col="blue")

16 Jitter plot nukerisk by scicomp

17 Bubble plot nukerisk by scicomp

18 Combined jitter-bubble plot nukerisk by scicomp


Download ppt "Plotting risk perceptions vs. political orientation & science comprehension Steve Genco August 19, 2015."

Similar presentations


Ads by Google