Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions Exercise10_Answer.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#navigate to working directory
setwd("C:Desktop/R Studio Projects/Biocomp_tutorial12/")

#load packages
library(ggplot2)
library(cowplot)

## Problem 1
#outside data used from research project on Age and Pregnancy Occurance
research <- read_csv("research.csv")
View(research)
research <- read.table("research.csv", header = TRUE, sep = ',',stringsAsFactors = FALSE)

fig1 <- ggplot(research, aes(x = Age, y = Pregnancies)) +
stat_smooth(method="loess") +
geom_point() +
theme_classic() +
xlab("Age (years)") +
ylab("Pregnancies") +
ggtitle("Age v. Number of Pregnancies")

##Problem 2
#import and read data
data = read.table("data.txt", header=TRUE, sep=",", stringsAsFactors = FALSE)

#barplot
fig2 <- ggplot(data, aes(x = region, y = observations)) +
stat_summary(fun = mean, geom = "bar") +
xlab("Region") +
ylab("Average Population") +
theme_classic()

#scatterplot
fig3 <- ggplot(data = data, aes(x = region, y = observations)) +
geom_point() +
geom_jitter() +
xlab("Region") +
ylab("Observation") +
theme_classic()