【发布时间】:2021-05-12 15:48:06
【问题描述】:
大家,
我有以下数据集(称为演示)。
Nation GDP FHouse OECD regime
1 Albania 3719 4.5 0 not free
2 Algeria 5327 5.5 0 not free
3 Angola 1462 6.0 0 not free
4 Argentina 12095 1.5 0 free
5 Armenia 2421 4.0 0 not free
6 Australia 27390 1.0 1 free
我做了一个图,绘制了一个 GDP 和 Fhouse 的图。
plot(demo$GDP, demo$FHouse, xlab = "Country's GDP", ylab = "Freedom House Rating", pch=16, xlim = c(500,5000), family="serif")
现在,我被要求根据制度(免费、非免费、部分免费)为每个点着色。我一直在阅读,显然我可以使用ifelse,但是我不知道如何给它三个条件,以便每个国家都根据免费,不免费和部分免费来着色。
谢谢大家。
【问题讨论】:
-
一个更简单的方法是使用
factors:plot(mpg ~ wt, mtcars, col = factor(gear))你也可以这样设置自定义颜色:plot(mpg ~ wt, mtcars, col = c('red', 'blue', 'orange')[factor(gear)])