library(hanoverbase)
data(counties) View(counties) # Only in console help(counties) # Only in console
## Heading here
### Heading here
*text here*
**text here**
1. text here
- text here
> text here
favstats(~pop2010, data=counties) favstats(miles~direction, data=driving) # miles by direction favstats(~miles|direction, data=driving) # same thing
median(~female|state, data=counties) %>% sort() iqr(~poverty|state, data=counties)
tally(~state, data=counties) tally(~state, data=counties) %>% sort()
tally(~genhealth, data=brfss, format="percent")
# Column-wise percents tally(~genhealth|sex, data=brfss, format="percent", useNA="no") # Total percents tally(~genhealth+sex, data=brfss, format="percent", useNA="no")
cor(mort_rate~own_rate, data=guns)
tally(~genhealth, data=brfss, useNA="no") %>% pie()
histogram(~pop2010, data=counties, breaks=20) histogram(~pop2010, data=counties %>% filter(pop2010 <= 2e6))
tally(~state, data=counties) %>% barchart() tally(~state, data=counties) %>% sort() %>% barchart() # Pareto chart
sum(~own_rate|country, data=guns) %>% sort() %>% dotplot()
healthVsExer <- tally(~genhealth|exerciseany, data=brfss, format="percent", useNA="no") healthVsExer %>% t() %>% barchart(auto.key=list(space="right"))
xyplot(mort_rate~own_rate, data=guns) ladd(panel.loess(x, y, col="magenta", lwd=2)) # add smooth fit line
bwplot(state~female, data=counties)
xyplot(mort_rate~own_rate|hdicat, data=guns)
colors() # in console
display.brewer.all() # in console
brewer.pal(4, "Accent")
...plot...(..., col=name-or-palette, ...)
...plot...(..., main="Distribution of ...", ...)
...plot...(..., xlab="x label here", ...) ...plot...(..., ylab="y label here", ...)
ladd(panel.lmline(x, y, col="magenta", lwd=2))
fit <- lm(mort_rate~own_rate, data=guns) coefficients(fit) summary(fit)
xyplot(resid(fit)~fitted(fit)) # residual plot ladd(panel.abline(h=0)) cor(mort_rate~own_rate, data=guns)^2 # r-squared