我发现 R 的默认绘图的别名很差。作为解决方案,我将 Cairo 设置为图形设备,现在绘图看起来好多了。
不幸的是,使用 Cairo 产生了另一个问题,即由于某种原因,我无法应用在绘图窗口中显示图形时使用的字体(在上面的左图中,使用了 Cambria,但右图未能应用此字体)。
这是我的代码:
library(readxl)
library(scales)
library(ggplot2)
library(dplyr)
library('Cairo')
windowsFonts(Cam = windowsFont("Cambria"))
dataset <- read_excel('CW Data.xlsx')
colnames(dataset)[4] <- "Broadband Subs (%)"
options(scipen = 1000)
# Scatter plot FDI~GDP with regression line
CairoWin()
ggplot(dataset, aes(x=`2019 GDP ($bn)`, y=`2019 FDI ($m)`)) +
geom_point(size=3, shape=1) +
geom_smooth(method='lm',formula=y~x, se=FALSE, color='black') +
scale_x_continuous(label = comma) + scale_y_continuous(label=comma) +
theme(panel.background = element_rect(fill="peachpuff"),
plot.background = element_rect(fill="peachpuff")) +
theme(panel.grid.major = element_line(colour = "gray72"),
panel.grid.minor = element_line(colour = "gray72")) +
theme(text = element_text(family …Run Code Online (Sandbox Code Playgroud)