I want to create a plot with ggplot's nice framework. It is a density plot with hexagons. I have used the sample code from https://www.r-graph-gallery.com/329-hexbin-map-for-distribution/
The graphic is nice, but I want to have these hexagons if the threshold is met. For example: Plot all values if the number is greater than 4.
Is there an opportunity to save the underlying aggregated data? I want to use them for further tests of pattern similarity. Therefore I want to remove points with four observation or less.
usually one can extract data via
object <- Function_that_produces_object
object$Data_I_Want_have
I have looked in the documentation, but there is written how to increase the size of Letters but not the number and the range of shown levels.
Packages
library(tidyverse)
library(viridis)
library(ggplot2)
# Get the GPS coordinates of a set of 200k tweets:
data=read.table("https://www.r-graph-gallery.com/wp-content/uploads/2017/12/Coordinate_Surf_Tweets.csv", sep=",", header=T)
# Get the world polygon
library(mapdata)
world <- map_data("world")
data %>%
filter(homecontinent=='Europe') %>%
ggplot( aes(x=homelon, y=homelat)) +
geom_hex(bins=65) +
theme_void() +
xlim(-30, 70) +
ylim(24, 72) +
scale_fill_viridis(option="B",
trans = "log",
name="Number of Tweet recorded in 8 months",
guide = guide_legend( keyheight = unit(3, units = "mm"), keywidth=unit(12, units = "mm"), label.position = "bottom", title.position = 'top', nrow=1)
) +
ggtitle( "Where people tweet about #Surf" ) +
theme(
legend.position = c(0.5, 0.09),
text = element_text(color = "#22211d"),
plot.background = element_rect(fill = "#f5f5f2", color = NA),
panel.background = element_rect(fill = "#f5f5f2", color = NA),
legend.background = element_rect(fill = "#f5f5f2", color = NA),
plot.title = element_text(size= 22, hjust=0.1, color = "#4e4d47", margin = margin(b = -0.1, t = 0.4, l = 2, unit = "cm")),
)