'tmap raster layer not rendering pixels full size

I'm trying to produce a basic heatmap and the grid pixels are rendering very small.

require(tmap)
require(dplyr)
require(stars)

d = data.frame(lon = rnorm(1e5, mean = -95.5, sd=4),
               lat = rnorm(1e5, mean = 37.5, sd=4)) |> 
  group_by(lat = round(lat), lon = round(lon)) |> 
  summarise(n = length(lat), .groups = 'drop') |> 
  st_as_sf(coords = c('lon','lat'), crs = 'WGS84') |>
  st_rasterize()

tmap_mode("view")

tm_basemap("Stamen.TonerLite") +
  tm_shape(d) +
  tm_raster("n", palette = c('white','red'), alpha=0.5)

enter image description here

enter image description here

Grateful for any suggestions what I'm doing wrong here.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source