fix opacity
This commit is contained in:
@@ -57,11 +57,27 @@ text(x = barplot(percentage, plot = FALSE),
|
||||
# 2. Create a stacked barchart that represents all site and their health data
|
||||
##
|
||||
|
||||
# Create data
|
||||
set.seed(1124)
|
||||
# Convert tree_health_index to factor for correct ordering in the barplot
|
||||
df$tree_health_index <- factor(df$tree_health_index, levels = 0:4, ordered = TRUE)
|
||||
|
||||
# Create a new data frame with counts of each health index for each site
|
||||
health_counts <- df %>%
|
||||
group_by(site_num, tree_health_index) %>%
|
||||
summarise(count = n())
|
||||
|
||||
# Pivot the data frame to wide format for ggplot
|
||||
health_counts_wide <- pivot_wider(health_counts, names_from = tree_health_index, values_from = count, values_fill = list(count = 0))
|
||||
|
||||
ggplot(health_counts_wide, aes(x = site_num)) +
|
||||
geom_bar(aes(fill = `0`), position = "stack", width = 0.5) +
|
||||
geom_bar(aes(fill = `1`), position = "stack", width = 0.5) +
|
||||
geom_bar(aes(fill = `2`), position = "stack", width = 0.5) +
|
||||
geom_bar(aes(fill = `3`), position = "stack", width = 0.5) +
|
||||
geom_bar(aes(fill = `4`), position = "stack", width = 0.5) +
|
||||
labs(x = "Site Number", y = "Count", fill = "Health Index") +
|
||||
scale_fill_manual(values = c("#1b9e77", "#d95f02", "#7570b3", "#e7298a", "#66a61e")) + # Custom colors for each health index
|
||||
theme_minimal()
|
||||
|
||||
# for each site i need a table like this:
|
||||
#table(df$tree_health_index[1:14])
|
||||
|
||||
colnames(health_data) <- paste("Site", seq(1,20), sep=" ")
|
||||
rownames(health_data) <- condition_names
|
||||
@@ -108,12 +124,17 @@ map <- leaflet() %>%
|
||||
setView(lng = population_lon,
|
||||
lat = population_lat,
|
||||
zoom = 16) %>%
|
||||
addTiles() %>%
|
||||
addProviderTiles(
|
||||
provider = "Esri.WorldImagery",
|
||||
options = providerTileOptions(
|
||||
opacity = 0.5
|
||||
)
|
||||
) %>%
|
||||
addCircleMarkers(
|
||||
data = df,
|
||||
lng = ~tree_lon,
|
||||
lat = ~tree_lat,
|
||||
radius = 2,
|
||||
radius = 1,
|
||||
color = ~condition_colors[tree_health_index+1],
|
||||
opacity = 1,
|
||||
fillOpacity = 1
|
||||
@@ -122,10 +143,10 @@ map <- leaflet() %>%
|
||||
data = sites,
|
||||
lng = ~site_lon,
|
||||
lat = ~site_lat,
|
||||
radius = 25,
|
||||
radius = 40,
|
||||
fill = FALSE,
|
||||
color = "green",
|
||||
opacity = 0.1
|
||||
color = "black",
|
||||
opacity = 0.5
|
||||
)
|
||||
|
||||
# show map
|
||||
|
||||
Reference in New Issue
Block a user