diamonds

R:ggplot2数据可视化――基础知识

匿名 (未验证) 提交于 2019-12-02 23:59:01
# 获取ggplot2 最容易的就是下载整个tidyverse: install.packages("tidyverse") # 也可以选择只下载ggplot2: install.packages("ggplot2") # 或者下载GitHub上的开发者版本 # install.packages("devtools") devtools::install_github("tidyverse/ggplot2") library(ggplot2) ggplot(diamonds) #以diamonds数据集为例 #gg <- ggplot(df, aes(x=xcol, y=ycol)) 其中df只能是数据框 ggplot(diamonds, aes(x=carat)) # 如果只有X-axis值 Y-axis can be specified in respective geoms. ggplot(diamonds, aes(x=carat, y=price)) # if both X and Y axes are fixed for all layers. ggplot(diamonds, aes(x=carat, color=cut)) # 'cut' 变量每种类型单独一个颜色, once a geom is added. #aes代表美化格式 ggplot2 把 X 和 Y