0% found this document useful (0 votes)
9 views1 page

R Code RPB Abundance Over Time

R code RPB abundance over time

Uploaded by

Arghya Paul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views1 page

R Code RPB Abundance Over Time

R code RPB abundance over time

Uploaded by

Arghya Paul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

# Ensure ggplot2 is installed and loaded

if (!requireNamespace("ggplot2", quietly = TRUE)) {


install.packages("ggplot2")
}
library(ggplot2)

# Ensure grid is loaded


library(grid)

# Load the data


data <- read.csv("E:\\RPB ADundance season.csv")

# Clean and prepare the data


data$Days_after_transplanting <- as.numeric(gsub("d", "",
data$Days.after.transplanting))
data$Number_of_red_pumpkin_beetle <- as.numeric(data$Number.of.red.pumpkin.beetle)

# Calculate the 5% standard error


data$Standard_error <- data$Number_of_red_pumpkin_beetle * 0.05

# Create the plot


p <- ggplot(data, aes(x = Days_after_transplanting, y =
Number_of_red_pumpkin_beetle)) +
geom_line(color = "cyan4", size = 1) +
geom_point(shape = 17, color = "darkolivegreen4", size = 4) + # shape 17 is for
triangles
geom_errorbar(aes(ymin = Number_of_red_pumpkin_beetle - Standard_error, ymax =
Number_of_red_pumpkin_beetle + Standard_error),
width = 0.2, color = "lightcoral") +
labs(title = "Red Pumpkin Beetle Abundance Over Time",
x = "Days After Transplanting",
y = "Number of Red Pumpkin Beetle") +
theme_minimal(base_size = 11) +
theme(plot.title = element_text(hjust = 0.5, face = "bold", size = 12),
axis.title = element_text(face = "bold", size = 10),
panel.grid.major = element_line(size = 0.5, linetype = 'dashed', colour =
"grey"),
panel.grid.minor = element_line(size = 0.25, linetype = 'dashed', colour =
"grey"))

# Function to draw a rounded rectangle background


draw_rounded_rect <- function() {
grid.roundrect(gp = gpar(fill = "white", col = "grey"), r = unit(0.1, "snpc"))
}

# Draw the plot with rounded rectangle background


grid.newpage()
pushViewport(viewport())
draw_rounded_rect()
print(p, newpage = FALSE)
popViewport()

You might also like