Line graphs: mapping temperature against time in the beaver1 dataset.
This list of linetypes is handy when setting up your graph.
# list of linetypes:
# 0=blank
# 1=solid
# 2=dashed
# 3=dotted
# 4=dotdash
# 5=longdash
# 6=twodash
We will draw, obviously, from the ggplot2 library. We’ll load the datasets library as well.
require(ggplot2)
## Loading required package: ggplot2
require(datasets)
The help documentaion offers this view of available shapes:
# Get a quick look at the available shapes for geom_point():
df2 <-data.frame(x=1:5, y=1:25, z=1:25)
s <- ggplot(df2, aes(x=x, y=y))
s + geom_point(aes(shape=z), size=4) + scale_shape_identity()

Let’s start with the beavers1 dataset. It has 114 rows and 4 columns.
The columns are named “day,” “time,” “temp,” and “activ.”
I’m going to rename the variables to avoid masking important objects.
beav <- beaver1
colnames(beav) <- c("proj.day", "proj.time", "proj.temp", "proj.activ")
beav2 <- beaver2
colnames(beav2) <- colnames(beav)
I will want to evaluate the two datasets against each other where
it is appropriate to do so. So let’s get them into one common data frame:
# using beaver1 and beaver2
beav2x <- rbind(beav, beav2)
Let’s create an ID column (think reshape package) wih factors spec1 and spec2:
specimen <- as.factor(c(rep("spec1", 114), rep("spec2", 100)))
beav2x <- cbind(beav2x, specimen)
colnames(beav2x)=c(colnames(beav),"proj.spec")
Sample Visualizations Below:
# attempt 1
ggplot(beav, aes(x=proj.time, y=proj.temp)) + geom_line()

That one was the basic “off the rack” ggplot line graph.
Next, let’s create a variable to hold the plot portion of that template:
gbeav <- ggplot(beav, aes(x=proj.time, y=proj.temp))
gbeav2 <- ggplot(beav2, aes(x=proj.time, y=proj.temp))
Now, let’s just run through a few improvisations:
# attempt 2
gbeav + geom_line() + geom_point()

# attempt 3
pdodg <- (position_dodge(2))
gbeav + geom_line(position=pdodg) +
geom_point(position=pdodg, size=3)
## ymax not defined: adjusting position using y instead
## ymax not defined: adjusting position using y instead

# attempt 4
gbeav + geom_line(linetype="dashed", size=0.5, color="red")

# attempt 5
gbeav + geom_line(linetype="longdash", size=0.8, color="blue")

# attempt 6
gbeav + geom_line(linetype="solid", size=1.5, color="red") +
geom_point(size=6, color="blue")

# attempt 7
gbeav + geom_line(linetype=2, size=1, color="blue")+
geom_point(shape=16, color="red", fill="white", size=3)

Theme Variations Below:
First we’ll get some redundancy out of the way:
beavline <- geom_line(linetype=3, size=1.1, color="blue")
beavpoint <- geom_point(shape=16, color="darkred", size=2.0)
beavtitle <- ggtitle("Beaver Temperatures Over Even Time Intervals")
beavggplot <- gbeav + beavline + beavpoint + beavtitle
Now let’s look at that graph against a few different backgrounds:
# attempt 8
beavggplot + theme_light()

# attempt 9
beavggplot + theme_classic()

# attempt 10
beavggplot + theme_minimal()

# attempt 11
beavggplot + theme_bw()

# attempt 12
beavggplot + theme_linedraw() # yuck

# go with bw, light, minimal, or classic!
Next up: visualizations using beaver1 and beaver2 datasets in one data frame