A line plot represents a data set in the form of straight lines joining the data points or markers (which are themselves often represented as dots, circles, squares, etc.).
Let’s use ggplot()
to draw the line plot for a simple dataset representing the solar irradiance (registered every 30 minutes during 24 hours) in Østerbø on July 22nd, 2017. Here are the variables and dataframe:
# ID
timepoint.ID <- 1:48
# variable1
solar.rad <- c(0,0,0,0,0,0,0,0,0,0,10,22,36,50,68,58,44,96,121,190,250,280,325,349,357,389,322,328,274,232,192,108,184,214,301,350,328,259,258,213,246,148,61,36,24,9,3,0)
# dataframe
df <- data.frame(timepoint.ID, solar.rad)
Now, let’s map the data from the variable solar.rad
by typing ggplot(df, aes(timepoint.ID, solar.rad))
and use geom_line()
to draw the line:
ggplot(df, aes(timepoint.ID, solar.rad)) +
geom_line()
We can improve the look of this plot by adding a few arguments to set a specific color and thickness of this line. It is also possible to define what type of line (dotted, solid, dashed, twodash, longdash, dotdash or blank) will be used:
ggplot(df, aes(timepoint.ID, solar.rad)) +
geom_line(colour="blue", size=1, linetype = "dotted")
We can also add a layer that will display the data points as large red dots by the mean of geom_point()
and the necessary arguments:
ggplot(df, aes(timepoint.ID, solar.rad)) +
geom_line(colour="blue") +
geom_point(size=3, colour="red", shape=16)
In this section, you will learn how to set/modify all the necessary elements that make a plot complete and comprehensible. Such elements are: