# 1. 지도, 라벨 출력 시 폰트가 깨지는 경우 (네모 박스)
ggplot(travel_add02, aes(x=lon, y=lat)) +
geom_polygon(data=world, aes(x=long, y=lat, group=group), fill="white", color="grey95") +
geom_point(color="grey", alpha=.55, aes(), size=3) +
geom_point(color="grey", alpha=.75, shape=1, aes(), size=3) +
geom_label_repel(aes(fill=factor(city), label=city), fontface="bold", color="white",
box.padding=0.35, point.padding=0.5, segment.color="grey70",
fontface="bold", size=09) +
theme(legend.position = 'none')
> ggplot(travel_add02, aes(x=lon, y=lat)) +
geom_polygon(data=world, aes(x=long, y=lat, group=group), fill="white", color="grey95") +
geom_point(color="grey", alpha=.55, aes(), size=3) +
geom_point(color="grey", alpha=.75, shape=1, aes(), size=3) +
geom_label_repel(aes(fill=factor(city), label=city), fontface="bold", color="white",
box.padding=0.35, point.padding=0.5, segment.color="grey70",
fontface="bold", size=09) +
theme(legend.position = 'none')
지도 출력 시 'geom_text', 'geom_label', 'geom_label_repel' 등을 사용하면 위와 같이 네모 박스만 출력되는 때가 있습니다. 이 경우는 코드에서 폰트(family) 지정을 해주지 않았을 때 생기는 경우가 대부분입니다. 폰트 지정을 해주지 않는 경우 (어딘가에서 설정된) 기본 폰트가 디폴트 값으로 사용되어 해당 언어의 문자를 출력할 수 없기 때문입니다. 출력 가능 폰트를 확인하기 위해 우선 'extrafont' 패키지의 'font_import'를 이용해 폰트를 불러옵니다. 그다음에는 'fonts'를 이용하여 사용 가능 폰트를 확인하고 그중 원하는 폰트를 family=에 넣어주면 됩니다.
> library(extrafont)
> font_import()
> fonts()
> fonts()
[1] ".Keyboard" "System Font" "Andale Mono" "Apple Braille"
[5] "AppleMyungjo" "Arial Black" "Arial" "Arial Narrow"
[9] "Arial Rounded MT Bold" "Arial Unicode MS" "Bodoni Ornaments" "Bodoni 72 Smallcaps"
[13] "Brush Script MT" "Comic Sans MS" "Courier New" "DIN Alternate"
[17] "DIN Condensed" "Georgia" "Impact" "Khmer Sangam MN"
[21] "Lao Sangam MN" "Luminari" "Microsoft Sans Serif" "Tahoma"
[25] "Times New Roman" "Trattatello" "Trebuchet MS" "Verdana"
[29] "Webdings" "Wingdings" "Wingdings 2" "Wingdings 3"
ggplot(travel_add02, aes(x=lon, y=lat)) +
geom_polygon(data=world, aes(x=long, y=lat, group=group), fill="white", color="grey95") +
geom_point(color="grey", alpha=.55, aes(), size=3) +
geom_point(color="grey", alpha=.75, shape=1, aes(), size=3) +
geom_label_repel(aes(fill=factor(city), label=city), fontface="bold", color="white",
box.padding=0.35, point.padding=0.5, segment.color="grey70",
fontface="bold", size=09, family="AppleGothic") +
theme(legend.position = 'none')
> ggplot(travel_add02, aes(x=lon, y=lat)) +
geom_polygon(data=world, aes(x=long, y=lat, group=group), fill="white", color="grey95") +
geom_point(color="grey", alpha=.55, aes(), size=3) +
geom_point(color="grey", alpha=.75, shape=1, aes(), size=3) +
geom_label_repel(aes(fill=factor(city), label=city), fontface="bold", color="white",
box.padding=0.35, point.padding=0.5, segment.color="grey70",
fontface="bold", size=09, family="AppleGothic") +
theme(legend.position = 'none')
'R project > 01' 카테고리의 다른 글
[R Project 01-1] 해시 태그가 포함된 명사 추출(정제) (0) | 2018.04.02 |
---|---|
[R Project 01-2] 복수 데이터 간의 교집합 추출 (0) | 2018.04.02 |
[R Project 01-3] 지도 출력을 위해 "geocode"로 위도, 경도 얻어오기 (0) | 2018.04.02 |
[R Project 01-4] "ggplot", "maps"를 이용한 지도 출력 (0) | 2018.04.02 |
(참고) [비교용 데이터] 위키피디아 자료로 국가 리스트 csv파일 만들기 (0) | 2018.04.02 |