I have created a ggplot2
graph that visualises the frequency of occurrence for different combinations of two factors. However, due to the large number of factors involved, it becomes challenging to interpret the plot effectively. To address this issue, I would like to add grid borders to the plot to improve its clarity and make it easier to understand.
The data used for the plot consists of two factors and a frequency value indicating how many times a specific combination occurred. Each factor represents a different category, and the frequency indicates the count of occurrences for each combination. How could I add grid border to make the data more readeable?
> str(data_df2)
'data.frame': 6111 obs. of 3 variables:
$ Lure : chr "Acrolepiopsis assectella" "Adoxophyes orana" "Apamea oblonga" "Archips rosana" ...
$ Species : Factor w/ 97 levels "Zeiraphera isertana",..: 97 97 97 97 97 97 97 97 97 97 ...
$ Frequency: int 0 0 0 0 0 0 0 0 0 0 ...
This is the code I used:
ggplot_obj2 <- ggplot(data = data_df2, aes(x = Lure, y = Species)) +
geom_tile(aes(fill = Frequency)) +
scale_fill_gradient(low = "gray90", high = "green4") +
labs(x = "Lure", y = "Species", fill = "Frequency") +
theme_bw() +
theme(axis.text.x = element_text(angle = 90, hjust = 1),
axis.text.y = element_text(size = 6),
legend.text = element_text(size = 8))
# Convert to plotly object
plotly_obj2 <- ggplotly(ggplot_obj2)
plotly_obj2