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

Base graphics using the default package

It is well known that R has very powerful data visualization capabilities. The primary reason behind the powerful graphical utility of R is the low-level graphical environment. The grid graphic system of R makes data visualization much more flexible and intuitive. With the help of the grid package, we can draw very basic shapes that can be arranged to produce interesting data visualizations. There are functions in the grid graphics system that draw very basic shapes of a high-level data visualization, including lines, rectangles, circles, and texts along with some other functions that specify where to put which part of the visualization. Through the use of the basic function, we can easily produce components of high-level graphs, such as a rectangle, rounded rectangle, circle, line, and arrow. We will now see how we can produce these basic shapes. In a single visualization, we will show you all the output from the following code snippet:

# Calling grid library
library(grid)

# Creating a rectangle
grid.rect(height=0.25,width=0.25)

# A rounded rectangle
grid.roundrect(height=0.2,width=0.2) 

# A circle
grid.circle(r=0.1)

# Inserting text within the shape
grid.text("R Graphics")
# Drawing a polygon
grid.polygon()

Basic shapes using the grid package

For any high-level visualization, we can use the basic shapes and arrange them as required. Now, we will list some of the functions for high-level data visualization where the basic shapes have been used:

  • plot: This is a generic function that is used to plot any kind of objects. Most commonly, we use this function for x-y plotting
  • barplot: This function is used to produce a horizontal or vertical bar plot
  • boxplot: This is used to produce a box-whisker plot
  • pie: This is used to produce a pie chart
  • hist: This is used to produce a histogram
  • dotchart: This is used to produce cleveland dot plots
  • image, heatmap, contour, and persp: These functions are used to generate image-like plots
  • qqnorm, qqline, and qqplot: These functions are used to produce plots in order to compare distributions

We will provide specific recipes for each of these functions in the subsequent chapters.

主站蜘蛛池模板: 垫江县| 宜昌市| 綦江县| 林周县| 阆中市| 山阴县| 冕宁县| 莒南县| 荃湾区| 山东省| 荃湾区| 盐城市| 民县| 汉中市| 驻马店市| 安新县| 新兴县| 鸡泽县| 拜泉县| 织金县| 三都| 清苑县| 郧西县| 钦州市| 呈贡县| 永福县| 长顺县| 仁寿县| 沭阳县| 绍兴市| 农安县| 鄂托克前旗| 嘉祥县| 雅安市| 罗山县| 望都县| 青铜峡市| 乌兰察布市| 罗城| 安康市| 武穴市|