User Tools

Site Tools


r:graphics

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
r:graphics [2016/12/02 09:44] – [E.G.] hkimscilr:graphics [2017/11/27 09:57] (current) – [Adding Confidence Intervals to a Bar Chart] hkimscil
Line 201: Line 201:
 title("Regression of MPG on Weight")</code> title("Regression of MPG on Weight")</code>
 {{:R:regression_line.png}} {{:R:regression_line.png}}
 +
 +===== e.g. 2 =====
 +
 +<code>?LifeCycleSavings
 +lm.SR <- lm(sr ~ pop15 + pop75 + dpi + ddpi, data = LifeCycleSavings)
 +
 +> summary(lm.SR)
 +
 +Call:
 +lm(formula = sr ~ pop15 + pop75 + dpi + ddpi, data = LifeCycleSavings)
 +
 +Residuals:
 +    Min      1Q  Median      3Q     Max 
 +-8.2422 -2.6857 -0.2488  2.4280  9.7509 
 +
 +Coefficients:
 +              Estimate Std. Error t value Pr(>|t|)    
 +(Intercept) 28.5660865  7.3545161   3.884 0.000334 ***
 +pop15       -0.4611931  0.1446422  -3.189 0.002603 ** 
 +pop75       -1.6914977  1.0835989  -1.561 0.125530    
 +dpi         -0.0003369  0.0009311  -0.362 0.719173    
 +ddpi         0.4096949  0.1961971   2.088 0.042471 *  
 +---
 +Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
 +
 +Residual standard error: 3.803 on 45 degrees of freedom
 +Multiple R-squared:  0.3385, Adjusted R-squared:  0.2797 
 +F-statistic: 5.756 on 4 and 45 DF,  p-value: 0.0007904
 +
 +> plot(LifeCycleSavings)
 +> plot(lm.SR)
 +</code>
 +
 +{{:r:LifeCycleSavings.jpeg}}
 +{{:R:regression_model.png}}
 +
 ====== Plotting All Variables Against All Other Variables ====== ====== Plotting All Variables Against All Other Variables ======
 <code>> head(iris) <code>> head(iris)
Line 385: Line 421:
 +         names.arg=c("May", "Jun", "Jul", "Aug", "Sep"), +         names.arg=c("May", "Jun", "Jul", "Aug", "Sep"),
 +         ylab="Temp (deg. F)")</code> +         ylab="Temp (deg. F)")</code>
-{{:R:barplot_heights.png}}+{{:R:barplot_heights.2.png}}
  
 ====== Adding Confidence Intervals to a Bar Chart ====== ====== Adding Confidence Intervals to a Bar Chart ======
Line 396: Line 432:
 </code> </code>
  
-<code>tmean <- tapply(Temp, list(as.factor(Month)), mean)  # mean for each month +<code>tmean <- tapply(Temp, list(as.factor(Month)), mean)   
-tsd <- tapply(Temp, list(as.factor(Month)),sd)  # sd for each month +# mean for each month 
-tse <- tsd/sqrt(length(Temp))  # se for each month+tsd <- tapply(Temp, list(as.factor(Month)),sd)   
 +# sd for each month 
 +tse <- tsd/sqrt(length(Temp))   
 +# se for each month
  
 lower <- tmean - 1.96*tse lower <- tmean - 1.96*tse
Line 433: Line 472:
 plot(pressure, type="l")</code> plot(pressure, type="l")</code>
 {{:R:barplot_points_line.png}} {{:R:barplot_points_line.png}}
 +
 +<code>> par(mfrow=c(2, 2), cex=0.6, mar=c(4, 4, 1, 1))
 +> y <- rnorm(20)
 +> plot(y, type="p")
 +> plot(y, type="l")
 +> plot(y, type="b")
 +> plot(y, type="h")
 +></code> 
 +{{:r:plot_types.png}}
 ====== Plotting Multiple Datasets ====== ====== Plotting Multiple Datasets ======
 <code>x <- rnorm(10,sd=5,mean=20) <code>x <- rnorm(10,sd=5,mean=20)
Line 897: Line 945:
 symbols(-.13, -0.8, circles=1, inches=0.1, add=TRUE)</code> symbols(-.13, -0.8, circles=1, inches=0.1, add=TRUE)</code>
 {{:R:using_maps_R.png}} {{:R:using_maps_R.png}}
 +
 +<code>par(mfrow=c(2, 2))
 +z <- 2 * volcano        # Exaggerate the relief
 +x <- 10 * (1:nrow(z))   # 10 meter spacing (S to N)
 +y <- 10 * (1:ncol(z))   # 10 meter spacing (E to W)
 +# Don't draw the grid lines :  border = NA
 +par(mar=rep(0, 4))
 +persp(x, y, z, theta = 135, phi = 30, col = "light grey", scale = FALSE,
 +      ltheta = -120, shade = 0.75, border = NA, box = FALSE)
 +mtext("persp()", side=3, line=-2)
 +par(mar=c(3, 3, 2, 0.5))
 +# Note that  example(trees)  shows more sensible plots!
 +N <- nrow(trees)
 +attach(trees)
 +# Girth is diameter in inches
 +symbols(Height, Volume, circles=Girth/24, inches=FALSE,
 +        main="", xlab="", ylab="", bg=grey(Girth/max(Girth)))
 +mtext("symbols()", side=3, line=0.5)
 +par(mar=rep(0.5, 4))
 +contour(x, y, z, asp=1, labcex=0.35, axes=FALSE)
 +rect(0, 0, 870, 620)
 +mtext("contour()", side=3, line=-1.5)
 +image(x, y, z, asp=1, col=grey(0.5 + 1:12/24), xlab="", ylab="", axes=FALSE)
 +rect(min(x)-5, min(y)-5, max(x)+5, max(y)+5)
 +mtext("image()", side=3, line=-1.5)
 +
 +
 +</code>
 +{{:R:poly_graph.png}}
  
r/graphics.1480641268.txt.gz · Last modified: 2016/12/02 09:44 by hkimscil

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki