使用ggplot2和特殊字符 [英] Using ggplot2 and special characters

查看:64
本文介绍了使用ggplot2和特殊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从网站读取数据,其中的文本标识每一行.我只是简单地将数据复制并粘贴到Excel中,然后R读取该文件.这些行之一包含德国城市的名称维尔茨堡",其中包括带有变音符号的小写u.我在网上或Excel上看到特殊字符没有问题.问题是,当将此单词传递给ggplot2时,它在图中显示为"WÃ zburg",并且在大写字母A上有波浪号.RStudio根据显示它的区域来显示两种形式.我假设 ggplot2 使用不同的语言来解释特殊字符.

I am reading in data from a web site, with text identifying each row. I simply copied and pasted the data into Excel, and the file is then read by R. One of these rows contains the name of a German city, "Würzburg", which includes a lower case u with an umlaut. I have no problem seeing the special character on the web or on Excel. The problem is, when this word is passed to ggplot2, it is displayed in the plot as "WÃzburg", with tilde over the capital A. RStudio shows both forms depending on the area in which it is displayed. I would assume that ggplot2 uses a different language for interpreting the special characters.

是否可以告诉ggplot如何阅读,解释和显示特殊字符?我不想只为这个城市编写专门的代码,而是要解决一般的问题.随着数据随着时间的增长,我可能还会遇到其他角色.

Is there a way to tell ggplot how to read, interpret and display the special characters? I do not want to write specialized code just for this city, but to solve the problem in general. I am likely to encounter other characters as the data expands over time.

推荐答案

按以下步骤读取文件

library('data.table')
fread('path_to_file', ..., encoding = 'UTF-8')

这篇关于使用ggplot2和特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆