wxy 2019/11/13
## -- Attaching packages --------------------------------------------------------------------------------------------------------------------------------------------- tidyverse 1.2.1 --
## √ ggplot2 3.2.1 √ purrr 0.3.2
## √ tibble 2.1.2 √ dplyr 0.8.3
## √ tidyr 1.0.0 √ stringr 1.4.0
## √ readr 1.3.1 √ forcats 0.4.0
## Warning: package 'ggplot2' was built under R version 3.6.1
## Warning: package 'tidyr' was built under R version 3.6.1
## Warning: package 'dplyr' was built under R version 3.6.1
## -- Conflicts ------------------------------------------------------------------------------------------------------------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
## Parsed with column specification:
## cols(
## age = col_double(),
## gender = col_double(),
## urban = col_double(),
## edu_expect = col_double(),
## parents_edu = col_double(),
## finc = col_double(),
## care_edu = col_double(),
## communicate = col_double(),
## total_care = col_double(),
## tutor_fees_log = col_double(),
## school_fees_log = col_double(),
## other_log = col_double()
## )
basic <- ggplot(child2016,aes(x = school_fees_log,y = other_log ,alpha = age)) +
geom_point(color = "red") +
theme_set(theme_bw()) +
labs(title = "HAPPY ")
basic ### 这个也不知道为什么没有用
## # A tibble: 6 x 11
## manufacturer model displ year cyl trans drv cty hwy fl class
## <chr> <chr> <dbl> <int> <int> <chr> <chr> <int> <int> <chr> <chr>
## 1 audi a4 1.8 1999 4 auto(~ f 18 29 p comp~
## 2 audi a4 1.8 1999 4 manua~ f 21 29 p comp~
## 3 audi a4 2 2008 4 manua~ f 20 31 p comp~
## 4 audi a4 2 2008 4 auto(~ f 21 30 p comp~
## 5 audi a4 2.8 1999 6 auto(~ f 16 26 p comp~
## 6 audi a4 2.8 1999 6 manua~ f 18 26 p comp~
## # A tibble: 6 x 11
## manufacturer model displ year cyl trans drv cty hwy fl class
## <chr> <chr> <dbl> <int> <int> <chr> <chr> <int> <int> <chr> <chr>
## 1 audi a4 1.8 1999 4 auto(~ f 18 29 p comp~
## 2 audi a4 1.8 1999 4 manua~ f 21 29 p comp~
## 3 audi a4 2 2008 4 manua~ f 20 31 p comp~
## 4 audi a4 2 2008 4 auto(~ f 21 30 p comp~
## 5 audi a4 2.8 1999 6 auto(~ f 16 26 p comp~
## 6 audi a4 2.8 1999 6 manua~ f 18 26 p comp~
## Warning: Removed 961 rows containing missing values (geom_point).
# 下面两种做法生成同样的结果,只是坐标刻度标签不同,建议用第一种
ggplot(child2016,aes(x = log10(school_fees_log),y = log10(other_log),color = "red")) +#对标度进行坐标变换(坐标轴的也一起变了)
geom_point()ggplot(child2016,aes(x = school_fees_log,y = other_log,color = "red")) +
geom_point() +
scale_x_log10() +#对数据进行变换(只变了数据,还是用的以前的坐标刻度,拉过去了)
scale_y_log10()## Warning: Transformation introduced infinite values in continuous x-axis
## Warning: Transformation introduced infinite values in continuous y-axis
f2d <- with(faithful,MASS::kde2d(eruptions,waiting,h = c(1,10),n = 50))
df <- with(f2d,cbind(expand.grid(x,y),as.vector(z)))
names(df) <- c("eruptions","waiting","density")
erupt <- ggplot(df,aes(waiting,eruptions,fill = density)) +
geom_tile() +
scale_x_continuous(expand = c(0,0)) +
scale_y_continuous(expand = c(0,0))
erupt + scale_fill_gradient(limits = c(0,0.04))ggplot(child2016,aes(x = school_fees_log,y = other_log,color = "red")) +
geom_point()+
scale_fill_gradient(low = "blue",high = "red")# library(vcd)
# fill_gradn <- function(pal){
# scale_fill_gradientn(colours = pal(7),limits = c(0,0.04))
# }
# erupt + fill_gradn(rainbow_hcl)
# erupt + fill_gradn(diverge_hcl)
# erupt + fill_gradn(heat_hcl)point <- qplot(brainwt,bodywt,data = msleep,log = "xy",colour = vore)
area <- qplot(log10(brainwt),data = msleep,fill = vore,binwidth = 1)
point + scale_colour_brewer(palette = "Set1")## Warning: Removed 32 rows containing missing values (geom_point).
## Warning: Removed 32 rows containing missing values (geom_point).
## Warning in pal_name(palette, type): Unknown palette PasteL1
## Warning in pal_name(palette, type): Removed 32 rows containing missing
## values (geom_point).
## Warning: Removed 27 rows containing non-finite values (stat_bin).
## Warning: Removed 27 rows containing non-finite values (stat_bin).
## Warning in pal_name(palette, type): Unknown palette PasteL1
## Warning: Removed 27 rows containing non-finite values (stat_bin).
## <ggproto object: Class ScaleDiscrete, Scale, gg>
## aesthetics: colour
## axis_order: function
## break_info: function
## break_positions: function
## breaks: waiver
## call: call
## clone: function
## dimension: function
## drop: TRUE
## expand: waiver
## get_breaks: function
## get_breaks_minor: function
## get_labels: function
## get_limits: function
## guide: legend
## is_discrete: function
## is_empty: function
## labels: waiver
## limits: NULL
## make_sec_title: function
## make_title: function
## map: function
## map_df: function
## n.breaks.cache: NULL
## na.translate: TRUE
## na.value: NA
## name: waiver
## palette: function
## palette.cache: NULL
## position: left
## range: <ggproto object: Class RangeDiscrete, Range, gg>
## range: NULL
## reset: function
## train: function
## super: <ggproto object: Class RangeDiscrete, Range, gg>
## reset: function
## scale_name: manual
## train: function
## train_df: function
## transform: function
## transform_df: function
## super: <ggproto object: Class ScaleDiscrete, Scale, gg>