This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
# Load the ggplot2 library
library(ggplot2)
# Aggregate the count of each species
species_count <- table(iris$Species)
# Convert the table to a data frame
species_df <- as.data.frame(species_count)
species_df$Species <- rownames(species_df)
# Create a bar graph
ggplot(species_df, aes(x = Species, y = Freq)) +
geom_bar(stat = "identity", fill = "skyblue") +
labs(title = "Bar Graph of Iris Species Counts", x = "Species", y = "Count")
# Load the ggplot2 library
library(ggplot2)
# Count the number of each species
species_count <- table(iris$Species)
# Create a pie chart
ggplot(data = as.data.frame(species_count), aes(x = "", y = Freq, fill = Var1)) +
geom_bar(stat = "identity") +
coord_polar(theta = "y") +
labs(title = "Pie Chart of Iris Species Proportions", fill = "Species") +
scale_fill_manual(values = c("setosa" = "red", "versicolor" = "green", "virginica" = "blue"))
# Load the ggplot2 library
library(ggplot2)
# Create a scatterplot for the Iris dataset
ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) +
geom_point() +
labs(title = "Scatterplot of Sepal Length vs. Sepal Width", x = "Sepal Length", y = "Sepal Width")
# Load the ggplot2 library
library(ggplot2)
# Create a box plot for the Iris dataset
ggplot(iris, aes(x = Species, y = Sepal.Length, fill = Species)) +
geom_boxplot() +
labs(title = "Box Plot of Sepal Length by Species", x = "Species", y = "Sepal Length")
summary(iris)
## Sepal.Length Sepal.Width Petal.Length Petal.Width
## Min. :4.300 Min. :2.000 Min. :1.000 Min. :0.100
## 1st Qu.:5.100 1st Qu.:2.800 1st Qu.:1.600 1st Qu.:0.300
## Median :5.800 Median :3.000 Median :4.350 Median :1.300
## Mean :5.843 Mean :3.057 Mean :3.758 Mean :1.199
## 3rd Qu.:6.400 3rd Qu.:3.300 3rd Qu.:5.100 3rd Qu.:1.800
## Max. :7.900 Max. :4.400 Max. :6.900 Max. :2.500
## Species
## setosa :50
## versicolor:50
## virginica :50
##
##
##
You can also embed plots, for example:
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.