Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Korean variable name is not working with ggplot2 #2665

Closed
statkclee opened this issue May 27, 2018 · 10 comments
Closed

Korean variable name is not working with ggplot2 #2665

statkclee opened this issue May 27, 2018 · 10 comments
Labels
bug an unexpected problem or unintended behavior
Milestone

Comments

@statkclee
Copy link

statkclee commented May 27, 2018

Korean variable name is not working

The dataframe has some Korean variable names. The variable name can be used normally with dplyr verbs, but variable name can not be recognized on the ggplot.

Whenever I version up(eg, 3.4.4 → 3.5.0 and previous versions), I experienced similar problems.

library(tidyverse)
# 1. data -----
sido_cl_df  <- read_rds("mac_sido_cl_df.rds")

str(sido_cl_df)
#> Classes 'tbl_df', 'tbl' and 'data.frame':    71 obs. of  14 variables:
#>  $ 선거구    : chr  "서울특별시" "서울특별시" "서울특별시" "서울특별시" ...
#>  $ 정당      : chr  "민주당" "자유한국" "바른미래" "정의" ...
#>  $ 성명      : chr  "박원순" "김문수" "안철수" "김종민" ...
#>  $ 성별      : chr  "남" "남" "남" "남" ...
#>  $ 주소      : chr  "서울특별시 종로구 북촌로6길" "서울특별시 관악구 승방10길" "서울특별시 노원구 동일로242나길" "서울특별시 용산구 백범로" ...
#>  $ 현직업    : chr  "공무원" "정당정치인" "정당정치인" "정당정치인" ...
#>  $ 전과      : int  0 1 0 2 0 0 0 0 4 0 ...
#>  $ 납부액    : int  94486 28589 19916104 648 231 2111 3992 18789 1697 471215 ...
#>  $ 현체납액  : int  0 0 0 0 0 0 0 0 0 0 ...
#>  $ 입후보횟수: int  2 7 3 4 0 0 1 1 0 3 ...
#>  $ 나이      : num  62 66 56 47 39 45 27 33 62 69 ...
#>  $ 학교      : chr  "단국대학교" "서울대학교" "서울대학교" "서강대학교" ...
#>  $ 학위      : chr  "학사" "학사" "박사" "학사" ...
#>  $ 사진      : chr  "http://info.nec.go.kr/photo_20180613/Sd1100/Sgg3110000/Hb100131769/gicho/thumbnail.100131769.JPEG" "http://info.nec.go.kr/photo_20180613/Sd1100/Sgg3110000/Hb100129583/gicho/thumbnail.100129583.JPG" "http://info.nec.go.kr/photo_20180613/Sd1100/Sgg3110000/Hb100128645/gicho/thumbnail.100128645.JPG" "http://info.nec.go.kr/photo_20180613/Sd1100/Sgg3110000/Hb100130904/gicho/thumbnail.100130904.JPG" ...

# 2. viz -----
## 2.1. error
sido_cl_df %>% 
    ggplot(aes(x=납부액, y=입후보횟수)) +
    geom_point() +
    scale_x_log10() +
    geom_smooth(stat="smooth")
#> Error in FUN(X[[i]], ...): 객체 '입후보횟수'를 찾을 수 없습니다

## 2.2. walkaround
sido_cl_df %>% 
    rename(num_run = "입후보횟수",
           pay_amt = "납부액") %>% 
    ggplot(aes(x=pay_amt, y=num_run)) +
    geom_point() +
    scale_x_log10() +
    geom_smooth(stat="smooth")
#> Warning: Transformation introduced infinite values in continuous x-axis

#> Warning: Transformation introduced infinite values in continuous x-axis
#> `geom_smooth()` using method = 'loess' and formula 'y ~ x'
#> Warning: Removed 2 rows containing non-finite values (stat_smooth).

Created on 2018-05-27 by the reprex package (v0.2.0).

Session info
devtools::session_info()
#> Session info -------------------------------------------------------------
#>  setting  value                       
#>  version  R version 3.5.0 (2018-04-23)
#>  system   x86_64, mingw32             
#>  ui       RTerm                       
#>  language (EN)                        
#>  collate  Korean_Korea.949            
#>  tz       Asia/Seoul                  
#>  date     2018-05-27
#> Packages -----------------------------------------------------------------
#>  package    * version    date       source                            
#>  assertthat   0.2.0      2017-04-11 CRAN (R 3.5.0)                    
#>  backports    1.1.2      2017-12-13 CRAN (R 3.5.0)                    
#>  base       * 3.5.0      2018-04-23 local                             
#>  bindr        0.1.1      2018-03-13 CRAN (R 3.5.0)                    
#>  bindrcpp     0.2.2      2018-03-29 CRAN (R 3.5.0)                    
#>  broom        0.4.4      2018-03-29 CRAN (R 3.5.0)                    
#>  cellranger   1.1.0      2016-07-27 CRAN (R 3.5.0)                    
#>  cli          1.0.0      2017-11-05 CRAN (R 3.5.0)                    
#>  colorspace   1.3-2      2016-12-14 CRAN (R 3.5.0)                    
#>  compiler     3.5.0      2018-04-23 local                             
#>  crayon       1.3.4      2017-09-16 CRAN (R 3.5.0)                    
#>  curl         3.2        2018-03-28 CRAN (R 3.5.0)                    
#>  datasets   * 3.5.0      2018-04-23 local                             
#>  devtools     1.13.5     2018-02-18 CRAN (R 3.5.0)                    
#>  digest       0.6.15     2018-01-28 CRAN (R 3.5.0)                    
#>  dplyr      * 0.7.5      2018-05-19 CRAN (R 3.5.0)                    
#>  evaluate     0.10.1     2017-06-24 CRAN (R 3.5.0)                    
#>  forcats    * 0.3.0      2018-02-19 CRAN (R 3.5.0)                    
#>  foreign      0.8-70     2017-11-28 CRAN (R 3.5.0)                    
#>  ggplot2    * 2.2.1.9000 2018-05-27 Github (tidyverse/ggplot2@1f9ef73)
#>  glue         1.2.0      2017-10-29 CRAN (R 3.5.0)                    
#>  graphics   * 3.5.0      2018-04-23 local                             
#>  grDevices  * 3.5.0      2018-04-23 local                             
#>  grid         3.5.0      2018-04-23 local                             
#>  gtable       0.2.0      2016-02-26 CRAN (R 3.5.0)                    
#>  haven        1.1.1      2018-01-18 CRAN (R 3.5.0)                    
#>  hms          0.4.2      2018-03-10 CRAN (R 3.5.0)                    
#>  htmltools    0.3.6      2017-04-28 CRAN (R 3.5.0)                    
#>  httr         1.3.1      2017-08-20 CRAN (R 3.5.0)                    
#>  jsonlite     1.5        2017-06-01 CRAN (R 3.5.0)                    
#>  knitr        1.20       2018-02-20 CRAN (R 3.5.0)                    
#>  labeling     0.3        2014-08-23 CRAN (R 3.5.0)                    
#>  lattice      0.20-35    2017-03-25 CRAN (R 3.5.0)                    
#>  lazyeval     0.2.1      2017-10-29 CRAN (R 3.5.0)                    
#>  lubridate    1.7.4      2018-04-11 CRAN (R 3.5.0)                    
#>  magrittr     1.5        2014-11-22 CRAN (R 3.5.0)                    
#>  memoise      1.1.0      2017-04-21 CRAN (R 3.5.0)                    
#>  methods    * 3.5.0      2018-04-23 local                             
#>  mime         0.5        2016-07-07 CRAN (R 3.5.0)                    
#>  mnormt       1.5-5      2016-10-15 CRAN (R 3.5.0)                    
#>  modelr       0.1.2      2018-05-11 CRAN (R 3.5.0)                    
#>  munsell      0.4.3      2016-02-13 CRAN (R 3.5.0)                    
#>  nlme         3.1-137    2018-04-07 CRAN (R 3.5.0)                    
#>  parallel     3.5.0      2018-04-23 local                             
#>  pillar       1.2.3      2018-05-25 CRAN (R 3.5.0)                    
#>  pkgconfig    2.0.1      2017-03-21 CRAN (R 3.5.0)                    
#>  plyr         1.8.4      2016-06-08 CRAN (R 3.5.0)                    
#>  psych        1.8.4      2018-05-06 CRAN (R 3.5.0)                    
#>  purrr      * 0.2.4      2017-10-18 CRAN (R 3.5.0)                    
#>  R6           2.2.2      2017-06-17 CRAN (R 3.5.0)                    
#>  Rcpp         0.12.17    2018-05-18 CRAN (R 3.5.0)                    
#>  readr      * 1.1.1      2017-05-16 CRAN (R 3.5.0)                    
#>  readxl       1.1.0      2018-04-20 CRAN (R 3.5.0)                    
#>  reshape2     1.4.3      2017-12-11 CRAN (R 3.5.0)                    
#>  rlang        0.2.0.9001 2018-05-27 Github (r-lib/rlang@88ac600)      
#>  rmarkdown    1.9        2018-03-01 CRAN (R 3.5.0)                    
#>  rprojroot    1.3-2      2018-01-03 CRAN (R 3.5.0)                    
#>  rvest        0.3.2      2016-06-17 CRAN (R 3.5.0)                    
#>  scales       0.5.0      2017-08-24 CRAN (R 3.5.0)                    
#>  stats      * 3.5.0      2018-04-23 local                             
#>  stringi      1.1.7      2018-03-12 CRAN (R 3.5.0)                    
#>  stringr    * 1.3.1      2018-05-10 CRAN (R 3.5.0)                    
#>  tibble     * 1.4.2      2018-01-22 CRAN (R 3.5.0)                    
#>  tidyr      * 0.8.1      2018-05-18 CRAN (R 3.5.0)                    
#>  tidyselect   0.2.4      2018-02-26 CRAN (R 3.5.0)                    
#>  tidyverse  * 1.2.1      2017-11-14 CRAN (R 3.5.0)                    
#>  tools        3.5.0      2018-04-23 local                             
#>  utils      * 3.5.0      2018-04-23 local                             
#>  withr        2.1.2      2018-03-15 CRAN (R 3.5.0)                    
#>  xml2         1.2.0      2018-01-24 CRAN (R 3.5.0)                    
#>  yaml         2.1.19     2018-05-01 CRAN (R 3.5.0)
@yutannihilation
Copy link
Member

yutannihilation commented May 27, 2018

Hi, I feel this part is not really reproducible:

sido_cl_df <- read_rds("mac_sido_cl_df.rds")

So, all I can do is only to guess, but maybe the names of your data.frame are encoded in UTF-8, right? (e.g. readr::read_csv() encodes the names as UTF-8) Could you show the result of Encoding(names(sido_cl_df))?

If it is UTF-8, probably this is the minimal reprex:

library(ggplot2)

d <- tibble::tibble(
  忍 = c(1, 1, 2, 2),
  者 = c(1, 2, 1, 2)
)

# OK
ggplot(d, aes(忍, 者)) +
  geom_point()

names(d) <- enc2utf8(names(d))

# Error
ggplot(d, aes(忍, 者)) +
  geom_point()
#> Error in FUN(X[[i]], ...): object '忍' not found

Created on 2018-05-27 by the reprex package (v0.2.0).

@statkclee

This comment has been minimized.

@statkclee

This comment has been minimized.

@yutannihilation
Copy link
Member

@statkclee
Thanks for confirming! 👍 For now, it seems safer to use enc2native()...

But, I feel this is a bug and should be fixed on rlang's side.

@hadley hadley reopened this May 28, 2018
@hadley hadley added the bug an unexpected problem or unintended behavior label May 28, 2018
@hadley hadley added this to the v2.3.0 milestone May 28, 2018
@hadley
Copy link
Member

hadley commented May 28, 2018

@lionel- can you please look into for ggplot2 release?

@lionel-
Copy link
Member

lionel- commented May 29, 2018

I think that should do it, could you please try with dev rlang?

@yutannihilation
Copy link
Member

Thanks! I confirmed this code works now w/ dev rlang: #2665 (comment)

@statkclee Could you confirm your code works as well?

@statkclee
Copy link
Author

Yes, it works... Thank you... @yutannihilation @lionel- @hadley

@yutannihilation
Copy link
Member

🎉

@lock
Copy link

lock bot commented Nov 26, 2018

This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

@lock lock bot locked and limited conversation to collaborators Nov 26, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

4 participants