# figure 1

library(ggplot2)
library(tidyr)


# figure 1 again
# Sample data
data <- data.frame(
  Month = c(
    "January-20", "February-20", "March-20", "April-20", "May-20", "June-20",
    "July-20", "August-20", "September-20", "October-20", "November-20", "December-20",
    "January-21", "February-21", "March-21", "April-21", "May-21", "June-21",
    "July-21", "August-21"
  ),
  Public_groups = c(8, 3, 4, 3, 2, 6, 7, 22, 9, 10, 12, 8, 4, 9, 5, 7, 14, 35, 51, 31),
  Closed_groups = c(0, 2, 0, 0, 0, 1, 0, 1, 0, 2, 0, 1, 0, 1, 1, 1, 2, 14, 3, 4)
)

# Remove hyphen from Month column
data$Month <- gsub("-", " ", data$Month)

# Convert Month to factor with correct order
data$Month <- factor(data$Month, levels = c(
  "January 20", "February 20", "March 20", "April 20", "May 20", "June 20",
  "July 20", "August 20", "September 20", "October 20", "November 20", "December 20",
  "January 21", "February 21", "March 21", "April 21", "May 21", "June 21",
  "July 21", "August 21"
))

# Reshape data for easier plotting
data_long <- tidyr::gather(data, key = "variable", value = "value", Public_groups, Closed_groups)

# Creating the line chart with ggplot2
ggplot(data_long, aes(x = Month, y = value, color = variable, group = variable)) +
  geom_line(size = 1.5) +  # Increase line thickness
  labs(x = 'Month', y = 'Number of Posts') +
  scale_color_manual(
    name = "Post type",
    values = c("Closed_groups" = "#333333", "Public_groups" = "#999999"),  # Darker and lighter grey
    labels = c("Closed group", "Public group")
  ) +
  theme_minimal() +
  theme(
    axis.text.x = element_text(angle = 45, hjust = 1),  # Rotate x-axis labels for better visibility
    legend.position = c(0.8, 0.85),  # Adjust legend position to top-right
    panel.grid = element_blank()  # Remove grid lines
  ) +
  guides(color = guide_legend(title = "Post type", reverse = TRUE))  # Reverse the legend order


# Install and load the ggplot2 package if not already installed
# install.packages("ggplot2")
library(ggplot2)

# Create a sample dataset
data <- data.frame(
  Reason = c("Box", 
             "Cloth", 
             "Crate", 
             "Foliage", 
             "Glue", 
             "Hand",
             "Leg chain",
             "Owner's cage",
             "Paper bag",
             "Plastic bag",
             "PVC Tube",
             "Rung",
             "Trapping cage"),
  Number = c(3, 6, 6, 1, 2, 25, 19, 173, 1, 3, 7, 6, 17)
)

# Reorder the data by Number in ascending order
data$Reason <- reorder(data$Reason, data$Number)

# Create a bar chart using ggplot2
ggplot(data, aes(x = Reason, y = Number, fill = Reason)) +
  geom_bar(stat = "identity", color = "black", width = 0.7) +
  theme_minimal() +
  theme(panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        axis.text.x = element_text(angle = 45, hjust = 1)) +
  labs(x = "Indicator of illegal capture",
       y = "Number of posts") +
  theme(plot.background = element_rect(color = "black", size = 1))




#Figure 4

library(ggplot2)

# Create a sample dataset
data <- data.frame(
  Reason = c("Box", 
             "Cloth", 
             "Crate", 
             "Foliage", 
             "Glue", 
             "Hand",
             "Paper bag",
             "Plastic bag",
             "PVC Tube"),
  Number = c(3, 6, 6, 1, 2, 25, 1, 3, 7)
)

# Reorder the data by Number in ascending order
data$Reason <- reorder(data$Reason, data$Number)

# Calculate the sum of the number of posts
total_posts <- sum(data$Number)

# Create a bar chart using ggplot2 with different shades of gray
ggplot(data, aes(x = Reason, y = Number, fill = Reason)) +
  geom_bar(stat = "identity", position = "dodge", width = 0.8, color = "black", fill = gray.colors(length(data$Reason), start = 0.2, end = 0.8)) +
  theme_minimal() +
  theme(panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        axis.text.x = element_text(angle = 45, hjust = 1),
        panel.border = element_rect(color = "black", fill = NA, size = 1),
        axis.line.x = element_line(color = "black", size = 1),
        axis.line.y = element_line(color = "black", size = 1),
        plot.margin = unit(c(1, 1, 1, 1), "cm"),
        plot.background = element_rect(color = "black")) +
  labs(x = "Indicator of illegal capture",
       y = "Number of posts") +
  scale_y_continuous(expand = expansion(mult = c(0, 0.05)))  # Adjust y-axis expansion

library(ggplot2)
library(dplyr)

# Sample data
data <- data.frame(
  Species = c(
    'Javan Hanging-parrot', 'Javan Hanging-parrot', 'Javan Hanging-parrot', 'Javan Hanging-parrot', 'Javan Hanging-parrot',
    'Blue-crowned Hanging-parrot', 'Blue-crowned Hanging-parrot', 'Blue-crowned Hanging-parrot', 'Blue-crowned Hanging-parrot',
    'Long-tailed Parakeet', 'Red Lory', 'Red Lory', 'Red Lory', 'Coconut Lorikeet', 'Blue-rumped Parrot', 'Blue-rumped Parrot'
  ),
  Price_IDR = c(70000, 100000, 250000, 100000, 250000, 110000, 70000, 25000,489635, 600000, 700000, 1300000, 1100000, 200000, 200000, 300000)
)

# Convert Price_IDR to numeric (remove commas)
data$Price_IDR <- as.numeric(gsub(",", "", data$Price_IDR))

# Creating the boxplot-like scatter plot with ggplot2
ggplot(data, aes(x = Species, y = Price_IDR, fill = Species)) +
  geom_boxplot(width = 0.5, outlier.shape = NA) +  # Boxplot without outliers
  geom_jitter(position = position_jitterdodge(dodge.width = 0.75, jitter.width = 0.2), size = 3, color = "black") +  # Jittered scatter plot
  scale_y_continuous(labels = scales::comma, breaks = seq(0, max(data$Price_IDR), by = 200000)) +  # Adjusting the number of tick marks
  labs(x = 'Bird Species', y = 'Price (Indonesian Rupiah, IDR)') +
  theme_minimal() +
  theme(
    axis.text.x = element_text(angle = 45, hjust = 1),  # Rotate x-axis labels for better visibility
    panel.grid.major = element_blank(),  # Remove major grid lines
    panel.grid.minor = element_blank(),  # Remove minor grid lines
    axis.title.y = element_text(vjust = 1)  # Add y-axis label with vertical adjustment
  )
