R language Qplot

Source: Internet
Author: User

Qplot means quick plot, which is part of the GGPLOT2 package, which needs to be loaded before the package is used.

Qplot Parameters:

Qplot (x, y = NULL, ..., data, facets = NULL, margins = FALSE,      geom = "Auto", Xlim = C (Na, NA), Ylim = C (Na, na), log = "",      main = null, Xlab = Deparse (Substitute (x)),      Ylab = Deparse (substitute (y)), ASP = NA, stat = null, Position = NULL)

Where: X and y represent the x-axis and y-axis
Facets for paging: Row_var~col_var
Geom represents a Geometry object:
# #geom = "point" scatter plot
# #geom = "Smooth" to fit smooth curves
# #geom = "path" connection (in any direction)
# #geom = "line" connection (left to right)

# #一维数据
# #连续变量
# #geom = "Histogram" histogram
# #geom = "Freqpoly" Frequency multi-figure
# #geom = "Density" density curve
# #离散变量
# #geom = "Bar" bar chart
Xlim and Ylim represent the range of values for the X and Y axes
Log represents a character vector that indicates which axis should take the logarithm. (log= "X" represents the logarithm of the x-axis, and log= "XY" indicates the logarithm of the XY axis)
Main represents the main caption of a graphic, which can be a string (main= "plot title") or an expression.
Xlab and Ylab represent the x-axis and y-axis text labels, with the same parameters as main
...

Test:

#install. Packages ("Ggplot2") Library (GGPLOT2) # #使用数据集diamondshead (Diamonds) Set.seed (1410) # #让样本可重复dsmall <- Diamonds[sample (Nrow (diamonds), +),] # #抽取100行qplot (carat, price, data = Diamonds) # #观察图形成指数增长qplot (log (carat), log (  Price), data = Diamonds) # #将数据对数化qplot (carat, price, data = Dsmall, colour =color) # #set颜色qplot (carat, price, data = Dsmall, Shape =cut) # #设置形状qplot (carat, price, data = Diamonds) # #观察图形重叠度太高, so set the transparency so that the overlap is darker qplot (carat, Price, DA Ta = diamonds, alpha = i (1/10)) # #其中1/10 means that after 10 overlaps the color becomes opaque qplot (carat, price, data = diamonds, alpha = i (1/100)) Qplot (Carat, price, data = diamonds, alpha = I (1/200)) # #qplot的集合对象 # #二维数据 # #geom = ' point ' scatter plot # #geom = ' smooth ' fit smooth curve # #  Geom = "path" line (any direction) # #geom = "line" connection (left to right) # #一维数据 # #连续变量 # #geom = "histogram" Histogram # #geom = "Freqpoly" Frequency multi-figure # #geom = "Density" Density curve # #离散变量 # #geom = "Bar" Bar # #平滑曲线 # #如果散点图中的数据太多, it is not easy to see the trend, you can add a smooth curve. Qplot (carat, price, data = Dsmall, Geom = C ("point", "Smooth")) # #注意几何对象会Stack qplot in order of C () (Carat, price, data = diamonds, Geom = C ("Smooth", "point")) # #先画smooth会使其被覆盖 # #曲线平滑程度, using the parameter span control, take a value of 0 (very  Not smooth) ~ 1 (very smooth) qplot (carat, price, data = Dsmall, Geom = C ("point", "smooth"), span = 0.2) qplot (carat, price, data = Dsmall, Geom = C ("point", "smooth"), span = 1) # #平滑曲线的灰色区间为置信区间qplot (carat, price, data = Dsmall, Geom = C ("point", "Smooth"), se = FALSE) # #如果不想绘制标准误差, you can use se=false# #平滑器的使用 # #n小于等于1000时, using method = "Loess" By default, using local regression methods. # #n大于1000时, by default use method = "Gam", Formula=y~s (x) to call the MGCV package to fit a generalized additive model. Qplot (carat, price, data = Dsmall, Geom = C ("point", "smooth"), method = "LM") # #使用现行模拟, get a straight line # #rlm与lm类型, when using a more robust fitting algorithm, make The result is not sensitive to outliers. (Need to load MASS package) library ("MASS") qplot (carat, price, data = Dsmall, Geom = C ("point", "smooth"), method = "RLM") # #箱线图和扰动点图 # #如 A dataset contains a categorical variable and one or more variables, and you want to know how the continuous variable changes with the level of the categorical variable. Qplot (color, price/carat, data = diamonds, Geom = "jitter", alpha = I (1/5)) # #扰动点图qplot (color, price/carat, data = Diamonds, Geom = "jitter", alpha = I (1/50) # #降低透明度, view the area in the dataset Qplot (color, price/carat, data = diamonds, Geom = "BoxPlot") # #箱线图 (display 4-bit points and outliers) Qplot (color, PRI Ce/carat, data = diamonds, Geom = "BoxPlot", colour = color) # #修改框架颜色qplot (color, price/carat, data = diamonds, Geo m = "BoxPlot", fill = color) # #修改填充 # #直方图和密度曲线图 # #直方图和密度曲线可以展示单个变量的分布, relative to the box plot, they provide more information about a single distribution,  But they're not easy to compare between different groups Qplot (carat, data = diamonds, Geom = "histogram") # #直方图qplot (carat, data = diamonds, Geom = "Density") # #密度图qplot (carat, data = diamonds, Geom = "Density", color = color) # #密度图, set the color # #对于密度曲线而言, the Adjust parameter controls how smooth the curve is (the greater the Adjust value, Smoother curve) Qplot (carat, data = diamonds, Geom = "density", adjust = 1) qplot (carat, data = diamonds, Geom = "Density", adjus t = 2) Qplot (carat, data = diamonds, Geom = "density", adjust = 3) # #对于直方图而言, the Binwith parameter adjusts the smoothness by setting the group distance # #在直方图中, you should try a variety of groups, when the group distance is large, The graph can reflect the general characteristics of the data, and when the group distance is small, more details can be displayed qplot (carat, data = diamonds, Geom = "Histogram", Binwidth =1, Xlim =c (0,3)) Qplot (Carat, data = diamonds, Geom = "Histogram", Binwidth =0.1, Xlim =c (0,3)) Qplot (carat, data = diamonds, Geom = "Histogram", Binwidth =0.01, Xlim =c (0,3)) # #条形图, in the case of discrete variables, the bar chart and the straight side Figure similar to Qplot (color, data = diamonds, Geom = "Bar") qplot (color, data =diamonds, Geom = "Bar", weight = carat) + Scale_y_c Ontinuous ("carat") # is weighted #按wight =carat, showing the total number of each color # #线条图与路径图 (typically used for time series) str (economics) qplot (date, unemploy/pop, data = Economics, Geom = "line") Qplot (date, uempmed, data = economics, Geom = "line") # #分组, the grouping of graphics can take advantage of graphic properties (color and shape), and all groups can be drawn in the same picture , you can also make facet # #分面: You can specify it by an expression such as Row_var~col_var, if you want to specify only one row or column to use. As a placeholder, such as row_var~. Creates a single-column, multi-line graph matrix Qplot (carat, data = Diamonds, facets = color~. , Geom = "Histogram", binwidth =0.1, Xlim = C (0,3)) Qplot (carat, data = diamonds, facets = color ~cut, Geom = "Histogram", binwidth =0.1, Xlim = C (0,3)) # # #. Density. Represents the mapping of density rather than frequency to the y-axis qplot (carat, ... Density. , data = diamonds, facets = color~. , Geom = "Histogram", binwidth =0.1, Xlim = C (0,3))

  

R language Qplot

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.