Giter Site home page Giter Site logo

aje-dotcom / testrepo Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 2.34 MB

The simplest form of the plot function that returns a scatterplot of the values vs the index, add lines to the function and add a title to make it easier to read and understand the plot in R. Here we add a line to the plot and to add a title. We specify the title function, create more beautiful visualizations using the ggplot libraries. ggplot is a data visualization package for R which handles complex requests allowing for you to add layers into plots by tweaking the functions and arguments. We will see an easier to read and understand graph. In our lab GGally extends ggplot2 by adding several functions to reduce the complexity of combining geometric objects with transformed data.

R 0.03% Python 2.18% HTML 1.80% Jupyter Notebook 95.99%
coursera coursework data data-visualization database datascience geometry ggally ggplot2 ibm-cloud

testrepo's Introduction

testrepo

Editing the File

Its a markdown repository

Objective for Exercise

We will create different data visualizations using the ggplotpackage using the inbuilt dataset in "R" called mtcars This is set up on (formerly Big Data University) by IBM Developer Skills Network lab

  1. Click on the + symbol on the top left and choose 'R Script' from the menu to open a new R edit window in RStudio image OR Hold CTRL + SHIFT + ALT + N
  2. Read and view the first 5 rows of the Data using the following:
library(datasets)

Load Data

data(mtcars)

View first 5 rows

head(mtcars, 5)
  1. Type this ?mtcars to get information about the variables. This will print the information at the bottom right panel, on the Help tab

  2. Copy and paste the following code to load the ggplot package and create a scatterplot of disp and mpg.

Load ggplot package

library(ggplot2) 2022-08-14 08_15_21-Skills Network Labs

create a scatterplot of displacement (disp) and miles per gallon (mpg)

ggplot(aes(x=disp,y=mpg,), data=mtcars)+ geom_point() 2022-08-15 06_24_45-Skills Network Labs

  1. Use the following code to add a title.

Add a title

 ggplot(aes(x=disp,y=mpg,), data=mtcars)+ geom_point()+ ggtitle("displacement vs miles per gallon")

2022-08-15 06_24_45-Skills Network Labs

  1. Use the following code to change the name of the x-axis and y-axis 2022-08-15 06_26_52-

change axis name

ggplot(aes(x=disp,y=mpg,), data=mtcars)+ geom_point()+ ggtitle("displacement vs miles per gallon") + labs(x = "Displacement", y = "Miles per Gallon")

2022-08-15 06_24_45-Skills Network Labs

  1. Use the following to create a boxplot of the the distribution of mpg for the individual Engine types vs Engine (0 = V-shaped, 1 = straight)

To do this you have to make vs a string or factor.

make vs a factor

mtcars$vs <- as.factor(mtcars$vs)

2022-08-15 06_26_52-

create boxplot of the distribution for v-shaped and straight Engine

ggplot(aes(x=vs, y=mpg), data = mtcars) + geom_boxplot()
  1. Add color to the boxplots to help differentiate:
ggplot(aes(x=vs, y=mpg, fill = vs), data = mtcars) + 
  geom_boxplot(alpha=0.3) +
  theme(legend.position="none")
  1. Finally, let us create the histogram of weight wt.
 ggplot(aes(x=wt), data=mtcars) + geom_histogram(binwidth=0.5)

This concludes this lab, I hope that you had fun!

Author(s)

 Ekene Emmanuel Ajemba 

testrepo's People

Contributors

aje-dotcom avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.