2017-10-20 17_45_02-Plot Zoom.png

A line graph in R, which can be generated by running the code in this post

Copy and paste the following code to your R Studio platform or R version:

# Visualizing data
# Introduction to ggplot2 package

install.packages(“ggplot2”)
library(ggplot2)

data(“mtcars”)
head(mtcars)
View(mtcars)
str(mtcars)

dot.plot <- ggplot(data = mtcars, aes(x = hp, y = mpg)) + geom_point()
dot.plot

# Let us put some colour in the graph
dot.plot.color <- ggplot(data = mtcars, aes(x = hp, y = mpg,
color = as.factor(cyl))) + geom_point()

# the as.factor statement functions as a break from using the cyl
# variable as continuous. Try the same code without the as.factor
# statement to see the difference

dot.plot.color

data(“pressure”)
head(pressure)
View(pressure)
str(pressure)

line.graph <- ggplot(data = pressure, aes(x = temperature, y = pressure)) +
geom_line() + geom_point()

line.graph

# Histogram – observe the distribution of a particular variable

histogram <- ggplot(data = mtcars, aes(x = mtcars$mpg)) +
geom_histogram(binwidth = 5)
histogram

Posted by Dimitris

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s