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

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.

主站蜘蛛池模板: 仁化县| 仪征市| 肥东县| 余江县| 吴桥县| 香河县| 青海省| 长沙县| 顺平县| 若尔盖县| 邛崃市| 凤阳县| 饶平县| 崇明县| 蒲城县| 牡丹江市| 布拖县| 乌拉特后旗| 鹤岗市| 青川县| 铁力市| 嘉祥县| 奎屯市| 海伦市| 文成县| 鄄城县| 盈江县| 湘西| 台前县| 西林县| 出国| 长葛市| 伊金霍洛旗| 罗山县| 丹棱县| 韩城市| 华容县| 湖南省| 清镇市| 博罗县| 黄山市|