OBJECTIVE: Controlling aesthetics like colour, size, legend and facets.

R Markdown

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:

Implementation of ggplot using Plantgrowth dataset

The “PlantGrowth” dataset is a built-in dataset in the R programming language that is commonly used for educational and illustrative purposes. The dataset provides information about the growth of plants under different fertilizer treatments.

library(ggplot2)
ggplot(PlantGrowth, aes(x = group, y = weight, color = group, size = weight)) +
  geom_point(alpha = 0.7) +
  scale_color_manual(values = c("blue", "red", "green")) +
  labs(
    title = "Effect of Fertilizers on Plant Growth",
    x = "Fertilizer Type",
    y = "Weight",
    color = "Fertilizer Type",
    size = "Weight"
  )

A plant weight by fertilizer type plot helps you visually assess the central tendency, spread, and distribution of plant weights under different fertilizer conditions. It is a useful tool for comparing the effects of different fertilizers on plant growth in a dataset.

ggplot(PlantGrowth, aes(x = weight, fill = group)) +
  geom_histogram(binwidth = 1, position = "identity", alpha = 0.7) +
  scale_fill_manual(values = c("blue", "red", "green")) +
  labs(
    title = "Histogram of Plant Weights by Fertilizer Type",
    x = "Weight",
    y = "Frequency",
    fill = "Fertilizer Type"
  )

ggplot(PlantGrowth, aes(x = group, y = weight, fill = group)) +
  geom_boxplot(alpha = 0.7) +
  scale_fill_manual(values = c("blue", "red", "green")) +
  labs(
    title = "Boxplot of Plant Weights by Fertilizer Type",
    x = "Fertilizer Type",
    y = "Weight",
    fill = "Fertilizer Type"
  )

ggplot(PlantGrowth, aes(x = weight, fill = group)) +
  geom_density(alpha = 0.7) +
  scale_fill_manual(values = c("blue", "red", "green")) +
  labs(
    title = "Density Plot of Plant Weights by Fertilizer Type",
    x = "Weight",
    fill = "Fertilizer Type"
  )

ggplot(PlantGrowth, aes(x = group, fill = group)) +
  geom_bar() +
  scale_fill_manual(values = c("blue", "red", "green")) +
  labs(
    title = "Bar Graph of Plant Weights by Fertilizer Type",
    x = "Fertilizer Type",
    y = "Count",
    fill = "Fertilizer Type"
  )

ggplot(PlantGrowth, aes(x = group, y = weight, fill = group)) +
  geom_violin(alpha = 0.7) +
  scale_fill_manual(values = c("blue", "red", "green")) +
  labs(
    title = "Violin Plot of Plant Weights by Fertilizer Type",
    x = "Fertilizer Type",
    y = "Weight",
    fill = "Fertilizer Type"
  )