I want to plot bubbles of my data.
Here is what I already have:
library(sp)
library(rgdal)
require(gstat)
setwd("C:/Users/49151/Desktop")
#import data
data <- read.csv("kerpentest0909x.csv")
head(data)
hist(data$Z, breaks = 20, xlab = "subsidence rates (mm/year)", main = "Histogram of subsidence at Kreuz Kerpen")
summary(data$Z)
#if slght skewedness
#data$Z.1 <- log10(data$Z)
#hist(data$Z.1, breaks = 10, xlab = "subsidence rates (mm/year)", main = "Histogram of subsidence at Kreuz Kerpen")
#convert data
coordinates(data) <- c("X", "Y")
#assigning projection
proj4string(data) <-CRS("+init=epsg:32632")
plot(data, asp=1, pch=1)
plot(data, asp=1, cex=4*data$Z/max(data$Z), pch=1)
The plot function gives me this:
It shows me just the high positive values. However I lack the R experience to do the following: Showing me both high negative and high positive values and a color distinction between both. If possible I'd like to see the values at each dot. here is my data:https://ufile.io/lne90ray
Here is an approach using sf
and ggplot2
...
To make the plot visually clearer, have added colour to the points and set alpha
to 0.5 as the plot is quite crowded. You can easily edit the appearance to suit your needs.
library(sf)
library(ggplot2)
#import data
data <- read.csv("kerpentest0909x.csv")
data1 <-
st_as_sf(data, coords = c("X", "Y"), crs = 32632)
ggplot() +
geom_sf(data = data1, aes(size = Z, fill = Z), shape = 21, alpha = 0.5)+
scale_fill_gradient(low = "red", high = "green")+
theme_bw()
Created on 2021-09-17 by the reprex package (v2.0.0)