Reputation: 1867
I am trying to do the map in ggplot2
in R
. I use this function from rgdal
package:
mapa <- readOGR(dsn=path.expand("C:/~/SWE_adm_shp"),layer="SWE_adm2")
than I do:
fortify(mapa)
ggplot(mapa, aes(x = long, y = lat, group = group)) +
geom_polygon(fill = "blue", col = "white") +
coord_map()
It works fine but when I look at the
head(mapa)
I see that the names of the counties dont have the Swedish font (NAME_2)
ID_0 ISO NAME_0 ID_1 NAME_1 ID_2 NAME_2 HASC_2 CCN_2 CCA_2 TYPE_2 ENGTYPE_2
0 222 SWE Sweden 1 Östergötland 1 Ödeshög SE.OG.OD 0 <NA> Kommuner Municipality
1 222 SWE Sweden 1 Östergötland 2 Åtvidaberg SE.OG.AT 0 <NA> Kommuner Municipality
2 222 SWE Sweden 1 Östergötland 3 Boxholm SE.OG.BO 0 <NA> Kommuner Municipality
3 222 SWE Sweden 1 Östergötland 4 Finspång SE.OG.FI 0 <NA> Kommuner Municipality
4 222 SWE Sweden 1 Östergötland 5 Kinda SE.OG.KI 0 <NA> Kommuner Municipality
5 222 SWE Sweden 1 Östergötland 6 Linköping SE.OG.LI 0 <NA> Kommuner Municipality
NL_NAME_2 VARNAME_2
0 <NA> <NA>
1 <NA> <NA>
2 <NA> <NA>
3 <NA> <NA>
4 <NA> <NA>
How to work over that?
> sessionInfo()
R version 3.3.2 (2016-10-31)
Platform: i386-w64-mingw32/i386 (32-bit)
Running under: Windows >= 8 x64 (build 9200)
locale:
[1] LC_COLLATE=Swedish_Sweden.1252 LC_CTYPE=Swedish_Sweden.1252 LC_MONETARY=Swedish_Sweden.1252
[4] LC_NUMERIC=C LC_TIME=Swedish_Sweden.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
Upvotes: 2
Views: 1348
Reputation: 12247
Try adding an encoding
parameter to your read:
mapa <- readOGR(dsn=path.expand("C:/~/SWE_adm_shp"),layer="SWE_adm2", encoding = "UTF-8")
to specify the encoding of the character set your file uses. It's a good bet that it will be UTF-8.
Upvotes: 3