Plot points relative to a value in dataframe

I have plotted concentrations of phosphate at their respective sampling sites. However, I have three different depths at which phosphate was measured. Can I make the geom points a particular size to represent the depth?

This is the code that I used to make the uploaded map.

world_coordinates <- map_data("world")
ggplot() + geom_map(
data = world_coordinates, map = world_coordinates,
aes(long, lat, map_id = region))

ggplot() + geom_map(
data = world_coordinates, map = world_coordinates,
aes(long, lat, map_id = region), color= "white", fill = "darkseagreen", size = 0.2) +
geom_point(data=Map_file, aes(x=longitude, y=latitude, color=PO4), size=4, alpha=0.5) +          scale_color_gradient2(low="white", mid="deeppink", high="darkorchid4", midpoint=1.5,            breaks=seq(0, 3, by=0.3)) +
theme_minimal() +
theme(plot.background = element_rect(fill = 'lightsteelblue', colour = 'white')) +
theme(panel.grid.major = element_line(size = 0.2, linetype = 'solid',
colour = "white")) +
labs(title = "DCM ocean layer (17-188 m) Phosphate Concentrations") +
theme(axis.title = element_text(face="bold", size = 16)) +
theme(axis.text = element_text(face = "bold", size=16, colour = "black")) +
geom_point(shape=21, aes(fill=Map_file$"Depth (m)", size="Map_file"$"PO4"))

Recognized by R Language Collective

You need to wrap size inside aes(), then you can use options from the scale_size() family. I have included two size plotting options, and have manually set the breaks. It can take trial and error to get the point sizes the way you want them (see the comparison of the first two plots to see what I mean). The final plot suggests that shape instead of size might be an appropriate option too.

For the sample PO4 data, I arbitrarily used 100m as the third depth. In the plot code below, there is a commented out option that shows how to use scale_size_area() for continuous values. These values will also work for scale_size() for your three depth values.

I made some adjustments to your plot code, such as restricting the background colour to just the panel area. It makes sense to do so IMHO. Another issue is that you only assigned colour in your aes() even though you want shape = 21. I have added the fill aesthetic and updated the plot code accordingly. Also, consider reducing the size of your axis text as it currently dominates your plot.

library(ggplot2)

# Map data
world_coordinates <- map_data("world")

# Example PO4 data
set.seed(42)
Map_file <- data.frame(id = 1:100,
                       depth = sample(c(17, 100, 188), 100, replace = TRUE),
                       PO4 = runif(100, 0, 3),
                       longitude = runif(100, -180, 180),
                       latitude = runif(100, -90, 90))

# Plot
ggplot() + 
  geom_map(data = world_coordinates, 
           map = world_coordinates,
           aes(map_id = region), 
           colour = "white",
           fill = "darkseagreen",
           linewidth = 0.2) +
  geom_point(data = Map_file,
             aes(x = longitude, y = latitude, fill = PO4, colour = PO4, size = depth), 
             alpha = 0.5,
             shape = 21) +
  scale_fill_gradient2(name = "PO4", 
                       low = "white", 
                       mid = "deeppink",
                       high = "darkorchid4",
                       midpoint = 1.5,
                       breaks = seq(0, 3, by = 0.3)) +
  scale_colour_gradient2(name = "PO4",  # Match names for single PO4 legend
                         low = "white", 
                         mid = "deeppink",
                         high = "darkorchid4",
                         midpoint = 1.5,
                         breaks = seq(0, 3, by = 0.3)) +
  scale_size(name = "Depth (m)",
             range = c(3, 6),
             breaks = c(17, 100, 188)) +
  # scale_size_area(name = "Depth (m)",
  #                 breaks = c(17, 80, 130, 188)) +
  labs(title = "DCM ocean layer (17-188 m) Phosphate Concentrations") +
  guides(size = guide_legend(override.aes = list(fill = "grey50", colour = "grey25"))) +
  expand_limits(x = world_coordinates$long, y = world_coordinates$lat) +
  coord_sf(expand = FALSE) +
  theme_minimal() +
  theme(panel.background = element_rect(fill = "lightsteelblue",
                                        colour = "white"),
        panel.grid.major = element_line(size = 0.2, linetype = "solid",
                                        colour = "white"),
        axis.title = element_text(face = "bold", size = 16),
        axis.text = element_text(face = "bold", size = 16, colour = "black"))

Note that in the above plot, it is difficult to differentiate between the points representing 100m and 188m. That’s because scale_size*() treats the values as continuous. Given you stated that you only have three sample depths, technically you have discrete values. Therefore, it may be more appropriate to use scale_size_manual(). To do so, if your depth values are numeric, you will need to convert them to factors e.g. size = factor(depth):

ggplot() + 
  geom_map(data = world_coordinates, 
           map = world_coordinates,
           aes(map_id = region), 
           colour = "white",
           fill = "darkseagreen",
           linewidth = 0.2) +
  geom_point(data = Map_file,
             aes(x = longitude, y = latitude, fill = PO4, colour = PO4, size = factor(depth)), 
             alpha = 0.5,
             shape = 21) +
  scale_fill_gradient2(name = "PO4", 
                       low = "white", 
                       mid = "deeppink",
                       high = "darkorchid4",
                       midpoint = 1.5,
                       breaks = seq(0, 3, by = 0.3)) +
  scale_colour_gradient2(name = "PO4",  # Match names for single PO4 legend
                         low = "white", 
                         mid = "deeppink",
                         high = "darkorchid4",
                         midpoint = 1.5,
                         breaks = seq(0, 3, by = 0.3)) +
  scale_size_manual(name = "Depth (m)",
                    values = c("17" = 3, "100" = 4.5, "188" = 6)) +
  labs(title = "DCM ocean layer (17-188 m) Phosphate Concentrations") +
  guides(size = guide_legend(override.aes = list(fill = "grey50", colour = "grey25"))) +
  expand_limits(x = world_coordinates$long, y = world_coordinates$lat) +
  coord_sf(expand = FALSE) +
  theme_minimal() +
  theme(panel.background = element_rect(fill = "lightsteelblue",
                                        colour = "white"),
        panel.grid.major = element_line(size = 0.2, linetype = "solid",
                                        colour = "white"),
        axis.title = element_text(face = "bold", size = 16),
        axis.text = element_text(face = "bold", size = 16, colour = "black"))

Given that your sample depth values are arguably discrete, there’s also a case for using shapes instead of size. Doing so makes your plot more explicitly communicate that there are only three sample depths even though the values represented are from a continuous metric (metres):

ggplot() + 
  geom_map(data = world_coordinates, 
           map = world_coordinates,
           aes(map_id = region), 
           colour = "white",
           fill = "darkseagreen",
           linewidth = 0.2) +
  geom_point(data = Map_file,
             aes(x = longitude, y = latitude, fill = PO4, colour = PO4, shape = factor(depth)), 
             alpha = 0.5,
             size = 3) +
  scale_fill_gradient2(name = "PO4", 
                       low = "white", 
                       mid = "deeppink",
                       high = "darkorchid4",
                       midpoint = 1.5,
                       breaks = seq(0, 3, by = 0.3)) +
  scale_colour_gradient2(name = "PO4",  # Match names for single PO4 legend
                         low = "white", 
                         mid = "deeppink",
                         high = "darkorchid4",
                         midpoint = 1.5,
                         breaks = seq(0, 3, by = 0.3)) +
  scale_shape_manual(name = "Depth (m)",
                    values = c(21, 22, 23)) +
  labs(title = "DCM ocean layer (17-188 m) Phosphate Concentrations") +
  guides(shape = guide_legend(override.aes = list(fill = "grey50", colour = "grey25"))) +
  expand_limits(x = world_coordinates$long, y = world_coordinates$lat) +
  coord_sf(expand = FALSE) +
  theme_minimal() +
  theme(panel.background = element_rect(fill = "lightsteelblue",
                                        colour = "white"),
        panel.grid.major = element_line(size = 0.2, linetype = "solid",
                                        colour = "white"),
        axis.title = element_text(face = "bold", size = 16),
        axis.text = element_text(face = "bold", size = 16, colour = "black"))

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật