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

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.

主站蜘蛛池模板: 津市市| 丹江口市| 桐柏县| 通江县| 广平县| 张家港市| 云梦县| 中方县| 长沙县| 蓝山县| 登封市| 静乐县| 崇礼县| 长泰县| 宝清县| 康马县| 镇坪县| 新干县| 偃师市| 霸州市| 托克托县| 安达市| 紫金县| 神农架林区| 东乡县| 福鼎市| 宿州市| 沅陵县| 怀宁县| 枞阳县| 鸡西市| 遂溪县| 达尔| 盘山县| 内江市| 灵武市| 铜鼓县| 稻城县| 札达县| 上林县| 万荣县|