References for Graphics, Tables, and Plots
|
|
library(ggthemes)
library(sjPlot)
library(sjmisc)
library(sjlabelled)
library(ggplot2)
lga <- readRDS(url("https://mqsociology.github.io/learn-r/soci832/nsw-lga-crime.RDS"))
lga$astdomviol <- set_label(lga$astdomviol, "Assault - domestic violence")
lga$astnondomviol <- set_label(lga$astnondomviol, "Assault - non-domestic violence")
lga$sexoff <- set_label(lga$sexoff, "Sexual Offences")
lga$robbery <- set_label(lga$robbery, "Robbery")
lga$brkentdwel <- set_label(lga$brkentdwel, "Break and entering dwelling")
lga$brkentnondwel <- set_label(lga$brkentnondwel, "Break and entering non-dwelling")
lga$mottheft <- set_label(lga$mottheft, "Motor vehicle theft")
lga$steafrmot <- set_label(lga$steafrmot, "Steal from motor vehicle")
lga$steafrsto <- set_label(lga$steafrsto, "Steal from retail store")
lga$steafrdwel <- set_label(lga$steafrdwel, "Steal from dwelling")
lga$steafrprsn <- set_label(lga$steafrprsn, "Steal from person")
lga$fraud <- set_label(lga$fraud, "Fraud")
lga$damtoprpty <- set_label(lga$damtoprpty, "Malicious damage to property")
lga$hrssthreat <- set_label(lga$hrssthreat, "Harassment and threatening")
lga$recvstlgoods <- set_label(lga$recvstlgoods, "Receiving stolen goods")
lga$oththeft <- set_label(lga$oththeft, "Other theft")
lga$arson <- set_label(lga$arson, "Arson")
lga$marijuana <- set_label(lga$marijuana, "Possession use of cannabis")
lga$weapon <- set_label(lga$weapon, "Prohibited weapons offences")
lga$trespass <- set_label(lga$trespass, "Trespass")
lga$offcond <- set_label(lga$offcond, "Offensive conduct")
lga$offlang <- set_label(lga$offlang, "Offensive language")
lga$liqoff <- set_label(lga$liqoff, "Liquor Offences")
lga$brchavo <- set_label(lga$brchavo, "Breach AVO")
lga$brchbailcon <- set_label(lga$brchbailcon, "Breach bail condition")
lga$rsthindofficer <- set_label(lga$rsthindofficer,"Resist or hinder officer")
lga$transport <- set_label(lga$transport, "Transport regulatory offences")
first <- which( colnames(lga)=="astdomviol" )
last <- which(colnames(lga)=="transport")
crimes <- lga[, first:last ]
returned_plot <- sjp.fa(crimes, nmbr.fctr = 3, rotation = c("promax"), method="minres", type = c("bar"), wrap.labels = 100, title = "Factor Analysis of NSW Crime Data")
## Loading required namespace: GPArotation
## Following items have no clear factor loading:
## robberyofflang
## returned_plot$plot + theme_solarized()
## returned_plot$plot + theme_few()
## returned_plot$plot + theme_classic()
## returned_plot$plot + theme_void()
## returned_plot$plot + theme_linedraw()
## returned_plot$plot + theme_minimal()
returned_plot$plot + theme_tufte()
returned_plot$plot + theme_tufte() + theme(axis.text.y = element_text(angle= 0, size = rel(.9)))
levels(returned_plot$plot$data$xpos) <- c("Factor 1", "Factor 2", "Factor 3")
returned_plot$plot + theme_tufte() + theme(axis.text.y = element_text(angle= 0, size = rel(.9)))
set_theme(
geom.outline.color = "antiquewhite4",
geom.outline.size = 0.5,
geom.label.color = "grey10",
title.color = "red",
title.size = 1.5,
axis.angle.x = 0,
axis.textcolor = "black",
base = theme_blank(),
axis.title.size = .9,
axis.textsize = .8,
legend.size = .7,
legend.title.size = .8,
geom.label.size = 3
)
set_theme(
base = theme_blank(),
geom.outline.color = "grey10",
geom.outline.size = 0.5,
geom.label.color = "green",
geom.label.size = 3,
title.color = "red",
title.size = 1.5,
axis.angle.x = 0,
axis.textcolor.x = "lightgreen",
axis.textcolor.y = "lightblue",
axis.title.size = .9,
axis.textsize = .8,
legend.size = .7,
legend.title.size = .8,
legend.title.color = "lightred",
)
returned_plot$plot + theme(plot.title = element_text(colour = 'red'))
# How to use CSS argument in sjt.* commands
crimes_table <- sjt.fa(crimes, nmbr.fctr = 3, rotation = c("promax"), method = "minres")
cat(crimes_table$page.style)
# <style>
# html, body { background-color: white; }
# table { border-collapse:collapse; border:none; }
# caption { font-weight: bold; text-align:left; }
# .thead { border-top:double black; padding:0.2cm; }
# .tdata { padding:0.2cm; }
# .cronbach { font-style:italic; border-bottom:double; border-bottom:double; }
# .minval { color:#cccccc; }
# .removable { background-color:#eacccc; }
# .firsttablerow { border-top:1px solid black; }
# .firsttablecol { }
# .centeralign { text-align:center; }
# .rightalign { text-align:right; }
# .rotation { font-style:italic; font-size:0.9em; }
# .comm { font-style:italic; color:#666666; }
# .kmo { font-style:italic; }
# .arc { background-color:#eaeaea; }
# </style>
crimes_table
# User defined style sheet
crimes_css <- list(css.table = "border: 2px solid;", css.thead = "border: 1px solid; text-align:centre;",
css.tr = "border: 1px solid; color:black;", css.td = "border: 1px solid;")
crimes_table_new <- sjt.fa(crimes, nmbr.fctr = 3, rotation = c("promax"), method = "minres",
CSS = crimes_css)
crimes_table_new
cat(crimes_table_new$page.style)
## <style>
## html, body { background-color: white; }
## table { border: 2px solid; }
## caption { font-weight: bold; text-align:left; }
## .thead { border: 1px solid; text-align:centre; }
## .tdata { padding:0.2cm; }
## .cronbach { font-style:italic; border-bottom:double; border-bottom:double; }
## .minval { color:#cccccc; }
## .removable { background-color:#eacccc; }
## .firsttablerow { border-top:1px solid black; }
## .firsttablecol { }
## .centeralign { text-align:center; }
## .rightalign { text-align:right; }
## .rotation { font-style:italic; font-size:0.9em; }
## .comm { font-style:italic; color:#666666; }
## .kmo { font-style:italic; }
## .arc { background-color:#eaeaea; }
## </style>
Last updated on 20 October, 2019 by Dr Nicholas Harrigan (nicholas.harrigan@mq.edu.au)