官术网_书友最值得收藏!

Highlighting grouped data points by size and symbol type

Sometimes, we might not want to use different colors to represent different groups of data points. For example, some journals accept graphs only in grayscale. In this recipe, we will learn how we can highlight grouped data points by symbol size and type.

Getting ready

We will use the ggplot2 library, so let's load it by running the following command:

library(ggplot2)

How to do it...

First, let's group points by the symbol type. Once again, we use the qplot() function:

qplot(disp,mpg,data=mtcars,shape=as.factor(cyl)) 

Next, let's group the points simply by the size of the plotting symbol:

qplot(disp,mpg,data=mtcars,size=as.factor(cyl))

How it works...

Highlighting groups of points by symbol type and size works exactly like colors using the qplot() functions. Instead of the col argument, we used the shape and size arguments and set them to the factor we want to group the points by (in this case, cyl). We can also use combinations of any of these arguments. For example, we can use colors to represent cyl and size to represent the gear.

主站蜘蛛池模板: 淮南市| 长治县| 崇阳县| 宣威市| 沿河| 鲁甸县| 靖远县| 屯门区| 中宁县| 犍为县| 喜德县| 张家口市| 桃园市| 公安县| 慈溪市| 平陆县| 敖汉旗| 师宗县| 大宁县| 济南市| 赞皇县| 洛阳市| 鄯善县| 左云县| 文成县| 长沙县| 永城市| 宁城县| 武川县| 额尔古纳市| 湟源县| 汉沽区| 文成县| 克什克腾旗| 天峨县| 类乌齐县| 东宁县| 无为县| 南阳市| 上林县| 汕头市|