Ggplot_Assignment1

docx

School

University of Illinois, Urbana Champaign *

*We aren’t endorsed by this school

Course

557

Subject

Electrical Engineering

Date

Apr 3, 2024

Type

docx

Pages

15

Uploaded by MajorDiscovery13494

Report
Ggplot_Assignment1 Swanand Shetwal 2024-02-05 R Markdown library (ggplot2) library (ggplot2movies) Q1.a. Using the “mtcars” dataset, plot a scatter plot where x=qsec and y=disp. add “cyl” as the facet and plot the graph. ggplot (mtcars, aes ( x = qsec, y = disp)) + geom_point () + facet_grid ( rows = vars (cyl))
Q1.b. Using the “mtcars” dataset, plot a graph where x=wt and y=hp. set the xlim from 2 to 6 and plot the graph with “gear” as the facet. add a smooth line to the graphs suppressWarnings ({ ggplot (mtcars, aes ( x = wt, y = hp)) + geom_point () + facet_grid ( rows = vars (gear)) + geom_smooth () + coord_cartesian ( xlim= c ( 2 , 6 )) }) ## `geom_smooth()` using method = 'loess' and formula = 'y ~ x' ## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric, ## : span too small. fewer data values than degrees of freedom. ## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric, ## : pseudoinverse used at 1.5027 ## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric, ## : neighborhood radius 1.2673 ## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric, ## : reciprocal condition number 0 ## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric, ## : There are other near singularities as well. 0.65656 ## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric, ## : Chernobyl! trL>n 5 ## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric, ## : Chernobyl! trL>n 5 ## Warning in sqrt(sum.squares/one.delta): NaNs produced ## Warning in predLoess(object$y, object$x, newx = if (is.null(newdata)) object$x ## else if (is.data.frame(newdata)) ## as.matrix(model.frame(delete.response(terms(object)), : span too
small. fewer ## data values than degrees of freedom. ## Warning in predLoess(object$y, object$x, newx = if (is.null(newdata)) object$x ## else if (is.data.frame(newdata)) ## as.matrix(model.frame(delete.response(terms(object)), : pseudoinverse used at ## 1.5027 ## Warning in predLoess(object$y, object$x, newx = if (is.null(newdata)) object$x ## else if (is.data.frame(newdata)) ## as.matrix(model.frame(delete.response(terms(object)), : neighborhood radius ## 1.2673 ## Warning in predLoess(object$y, object$x, newx = if (is.null(newdata)) object$x ## else if (is.data.frame(newdata)) ## as.matrix(model.frame(delete.response(terms(object)), : reciprocal condition ## number 0 ## Warning in predLoess(object$y, object$x, newx = if (is.null(newdata)) object$x ## else if (is.data.frame(newdata)) ## as.matrix(model.frame(delete.response(terms(object)), : There are other near ## singularities as well. 0.65656 ## Warning in stats::qt(level/2 + 0.5, pred$df): NaNs produced ## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning ## -Inf
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Q1.c. the “mtcars” dataset, plot a graph where x=drat and y=mpg. set the xlim from 2 to 5 and plot the graph with “cyl” as the facet. add a smooth line to the graphs suppressWarnings ({ ggplot (mtcars, aes ( x = drat, y = mpg)) + geom_point () + facet_grid ( rows = vars (cyl)) + geom_smooth () + coord_cartesian ( xlim= c ( 2 , 5 )) }) ## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric, ## : pseudoinverse used at 3.9258 ## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric, ## : neighborhood radius 0.3058 ## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric, ## : reciprocal condition number 0 ## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric, ## : There are other near singularities as well. 0.0784 ## Warning in predLoess(object$y, object$x, newx = if (is.null(newdata)) object$x ## else if (is.data.frame(newdata)) ## as.matrix(model.frame(delete.response(terms(object)), : pseudoinverse used at ## 3.9258 ## Warning in predLoess(object$y, object$x, newx = if (is.null(newdata)) object$x ## else if (is.data.frame(newdata)) ## as.matrix(model.frame(delete.response(terms(object)), : neighborhood radius ## 0.3058 ## Warning in predLoess(object$y, object$x, newx = if (is.null(newdata)) object$x ## else if (is.data.frame(newdata)) ## as.matrix(model.frame(delete.response(terms(object)), : reciprocal condition ## number 0 ## Warning in predLoess(object$y, object$x, newx = if (is.null(newdata)) object$x ## else if (is.data.frame(newdata)) ## as.matrix(model.frame(delete.response(terms(object)), : There are other near ## singularities as well. 0.0784
#—–Histogram head (attenu) ## event mag station dist accel ## 1 1 7.0 117 12 0.359 ## 2 2 7.4 1083 148 0.014 ## 3 2 7.4 1095 42 0.196 ## 4 2 7.4 283 85 0.135 ## 5 2 7.4 135 107 0.062 ## 6 2 7.4 475 109 0.054 Q3.a. Using the “attenu” dataset, plot a basic histogram for variable “mag” and set binwidth = 0.1. ggplot (attenu, aes ( x = mag)) + geom_histogram ( binwidth = 0.1 )
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Q3.b. For the graph obtained from Q3.a., set binwidth as 0.2, alpha as 0.3 with color and fill as per your choice ggplot (attenu, aes ( x = mag)) + geom_histogram ( binwidth = 0.2 , alpha = 0.3 , color = "blue" , fill = "orange" )
Q3.c. Using the “attenu” dataset, plot a histogram for variable “accel” and set the parameters as per your liking. ggplot (attenu, aes ( x = accel)) + geom_histogram ( binwidth = 0.5 , fill = "green" , color = "black" )
Scatter plots Q4.a. Using the “mtcars” dataset, plot a graph where x=drat and y=mpg, set size=10 and alpha=0.3. ggplot (mtcars, aes ( x = drat, y = mpg)) + geom_point ( size = 10 , alpha = 0.3 )
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Q4.b. For the graph obtained from Q4.a., define size using “disp” variable. ggplot (mtcars, aes ( x = drat, y = mpg, size = disp)) + geom_point ( alpha = 0.3 )
Q4.c. For the graph obtained from Q4.a., define shape and color using “gear” variable. ggplot (mtcars, aes ( x = drat, y = mpg, shape = factor (gear), color = factor (gear))) + geom_point ( size = 10 , alpha = 0.3 )
boxplot Q6.a. Using the “mpg” dataset, create a boxplot where x=cyl and y=hwy. ggplot (mpg, aes ( x = factor (cyl), y = hwy)) + geom_boxplot ()
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Q6.b. Using the “mtcars” dataset, create a boxplot where x=gear and y=hp. ggplot (mtcars, aes ( x = factor (gear), y = hp)) + geom_boxplot ()
Q6.c. Using the “mtcars” dataset, create a boxplot where x=am and y=wt. ggplot (mtcars, aes ( x = factor (am), y = wt)) + geom_boxplot ()
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help