Difficulty in map production

Hi guys,

I hope everyone is well at this time.

I am in the middle of an important assignment for university. I need to produce a map with the sites that were sampled during data collection. I have attached the code I have produced thus far. I am, however, struggling to complete the code.
If anyone could offer some suggestions I would greatly appreciate it.

Many thanks,

Boru

#Please find the code below:
library(maps)

Localisation of the file with all the coordinates

Sampling_coord <- read.csv()
#Project only islands
palette(c("yellow","green","red"))
#Create a file in output
png(, res=300, width = 15, height = 15, units = "cm")

coordinates of the area

map(xlim =c(-10,0), ylim=c(55,60), fill=F, col="black",mar=c(1,1,1,1))

Substract only the island samples

islands=subset(Sampling_coord, Project == 'Island')

Put the points on the map and color by type of site

points(islands$Long,islands$Lat,col=islands$SiteMiteBees,pch=19)

Put the labels on the sites

text(islands$Long, islands$Lat,label=islands$Code, cex=0.8, adj=1.4) legend("bottomright",legend=unique(islands$SiteMiteBees),pch=19,col=unique(islands$SiteMiteBees),cex=0.6) dev.off()

Please find the sites below:

58.223914;-6.386988;L;Island;Varroa;Honey Bees;Island + Varroa + Honey Bees
57.051801;-5.923568;S;Island;Varroa;Honey Bees;Island + Varroa + Honey Bees
56.598782;-6.627109;Coll;Island;Varroa;Honey Bees;Island + Varroa + Honey Bees
56.62349;-6.073362;Mull;Island;NoVarroa;Honey Bees;Island + Honey Bees
55.698677;-6.445954;I;Island;NoVarroa;Honey Bees;Island + Honey Bees
56.959589;-7.443962;B;Island;NoVarroa;Honey Bees;Island + Honey Bees
56.068724;-6.196989;C;Island;NoVarroa;Honey Bees;Island + Honey Bees
57.153458;-7.308724;SU;Island;NoVarroa;No Honey Bees;Island
57.084832;-7.310713;E;Island;NoVarroa;No Honey Bees;Island
57.010631;-6.265324;R;Island;NoVarroa;No Honey Bees;Island

`

Hi @Boru446,
Welcome to the RStudio Community Forum.
You were very close with your code. This version works with the data you provided:

a <- "
58.223914;-6.386988;L;Island;Varroa;Honey Bees;Island + Varroa + Honey Bees
57.051801;-5.923568;S;Island;Varroa;Honey Bees;Island + Varroa + Honey Bees
56.598782;-6.627109;Coll;Island;Varroa;Honey Bees;Island + Varroa + Honey Bees
56.62349;-6.073362;Mull;Island;NoVarroa;Honey Bees;Island + Honey Bees
55.698677;-6.445954;I;Island;NoVarroa;Honey Bees;Island + Honey Bees
56.959589;-7.443962;B;Island;NoVarroa;Honey Bees;Island + Honey Bees
56.068724;-6.196989;C;Island;NoVarroa;Honey Bees;Island + Honey Bees
57.153458;-7.308724;SU;Island;NoVarroa;No Honey Bees;Island
57.084832;-7.310713;E;Island;NoVarroa;No Honey Bees;Island
57.010631;-6.265324;R;Island;NoVarroa;No Honey Bees;Island"

islands <- read.delim(text=a, sep=";", header=FALSE)

names(islands) <- c("Lat","Long","Code","Land_type","mite","bees","SiteMiteBees")
islands

library(maps)

# coordinates of the area
map(xlim =c(-10,0), ylim=c(55,60), fill=F, col="black", mar=c(1,1,1,1))

# Put the points on the map and color by type of site
points(islands$Long, islands$Lat, col=islands$SiteMiteBees, pch=19)

# Put the labels on the sites
text(islands$Long, islands$Lat, label=islands$Code, cex=0.8, pos=2)

# Draw a legend
legend("bottomright", legend=unique(islands$SiteMiteBees), pch=19, 
       col=unique(islands$SiteMiteBees), cex=0.6)

# When the code is working as you want, copy it inside the png()....dev.off()
png("my_map.png", res=600, width = 15, height = 15, units = "cm")
  map(xlim =c(-10,0), ylim=c(55,60), fill=F, col="black", mar=c(1,1,1,1))
  points(islands$Long, islands$Lat, col=islands$SiteMiteBees, pch=19)
  text(islands$Long, islands$Lat, label=islands$Code, cex=0.8, pos=2)
  
  legend("bottomright", legend=unique(islands$SiteMiteBees), pch=19, 
         col=unique(islands$SiteMiteBees), cex=0.8)
dev.off()

HTH (from a fellow-bee-keeper!)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.