Antonio
Antonio

Reputation: 763

isobaths from SpatialLinesDataFrame are not well represented in fortified dataframe

I have a shapefile with isobaths from my study area and I easily imported it to R as a SpatialLinesDataFrame with

sdf.isobath <- readOGR("./gis","isobath")
sdf.isobath <- spTransform(sdf.isobath, CRS("+proj=longlat +datum=WGS84"))
proj4string(sdf.isobath)

plot(sdf.isobath)

isobath plot

Nevertheless I want to use in a ggplot map. To do so I "fortified" it.

# add id column with row names 
sdf.isobath$id <- rownames(sdf.isobath@data)

# create dataframe
dat.isobath_spc <- fortify(sdf.isobath,region="id")
head(dat.isobath_spc)

# add map data
dat.isobath_spc <- merge(dat.isobath_spc,sdf.isobath@data,by="id")
head(dat.isobath_spc)
summary(dat.isobath_spc)

But when I plot it with ggplot isolines are confused

ggplot() + geom_line(data = dat.isobath_spc, aes(x=long, y=lat, group=id), color="black",size=0.1)

ggplot map

I tried several shapefiles with isolines and had the same problem. Where am I going wrong?

Thanks.

Upvotes: 0

Views: 93

Answers (1)

Antonio
Antonio

Reputation: 763

I got the answer. I have to use geom_path

I have to use

ggplot() + geom_path(data = dat.isobath_spc, aes(x=long, y=lat, group=id), color="black",size=0.1)

rigth ggplot

Upvotes: 1

Related Questions