2 * 2[1] 4
2 * 2[1] 4
| mpg | cyl | disp | hp | drat | wt | qsec | vs | am | gear | |
|---|---|---|---|---|---|---|---|---|---|---|
| Mazda RX4 | 21.0 | 6 | 160.0 | 110 | 3.90 | 2.620 | 16.46 | 0 | 1 | 4 |
| Mazda RX4 Wag | 21.0 | 6 | 160.0 | 110 | 3.90 | 2.875 | 17.02 | 0 | 1 | 4 |
| Datsun 710 | 22.8 | 4 | 108.0 | 93 | 3.85 | 2.320 | 18.61 | 1 | 1 | 4 |
| Hornet 4 Drive | 21.4 | 6 | 258.0 | 110 | 3.08 | 3.215 | 19.44 | 1 | 0 | 3 |
| Hornet Sportabout | 18.7 | 8 | 360.0 | 175 | 3.15 | 3.440 | 17.02 | 0 | 0 | 3 |
| Valiant | 18.1 | 6 | 225.0 | 105 | 2.76 | 3.460 | 20.22 | 1 | 0 | 3 |
| Duster 360 | 14.3 | 8 | 360.0 | 245 | 3.21 | 3.570 | 15.84 | 0 | 0 | 3 |
| Merc 240D | 24.4 | 4 | 146.7 | 62 | 3.69 | 3.190 | 20.00 | 1 | 0 | 4 |
| Merc 230 | 22.8 | 4 | 140.8 | 95 | 3.92 | 3.150 | 22.90 | 1 | 0 | 4 |
| Merc 280 | 19.2 | 6 | 167.6 | 123 | 3.92 | 3.440 | 18.30 | 1 | 0 | 4 |
| Merc 280C | 17.8 | 6 | 167.6 | 123 | 3.92 | 3.440 | 18.90 | 1 | 0 | 4 |
f(x) = \frac{1}{2} \sum_{j=1}^\infty \int_0^1 \sin^2(j t x) dt .
定理 1 (勒贝格定理) 一元函数黎曼可积, 当且仅当其不连续点的集合为零测集。
引用如:见定理 1。
library(mgcv)
library(ggplot2)
ggplot(mpg,aes(displ,hwy)) +
geom_point() +
geom_smooth(method = "gam", formula = y ~ s(x)) +
theme_bw()参见图 1。
library(donutsk)
# Create an example data set
n <- 40
set.seed(2021)
df <- dplyr::tibble(
lvl1 = sample(LETTERS[1:5], n, TRUE),
lvl2 = sample(LETTERS[6:24], n, TRUE),
value = sample(1:20, n, TRUE),
highlight_ext = sample(c(FALSE,TRUE), n, TRUE, c(.9, .1))) |>
dplyr::mutate(highlight_int = dplyr::if_else(lvl1 == "A",TRUE,FALSE))
# Doubled donut with advanced labeling
dplyr::group_by(df, lvl1, lvl2, highlight_ext, highlight_int) |>
dplyr::summarise(value = sum(value), .groups = "drop") |>
# Pack values effectively
packing(value, lvl1) |>
ggplot(aes(value = value, fill = lvl1)) +
# The donutsk visualization functions
geom_donut_int(aes(highlight = highlight_int), alpha=.5, r_int = .25) +
geom_label_int(aes(label = "Sum {fill}:\n{.sum} ({scales::percent(.prc)})"),
alpha = .6, col = "white", r=1.2) +
geom_donut_ext(aes(opacity = lvl2, highlight = highlight_ext)) +
geom_label_ext(aes(label = paste0(lvl2, ": {scales::percent(.prc_grp)}")),
show.legend = FALSE, col="white",
layout = tv(thinner = TRUE)) +
geom_pin(size=.5, linewidth=.1, show.legend = FALSE, cut = .25,
layout = tv(thinner = TRUE)) +
# Additional appearance settings
scale_fill_viridis_d(option = "inferno", begin = .1, end = .7) +
theme_void() +
theme(legend.position = "none") +
coord_polar(theta = "y")library(hrbrthemes)
library(ggalt)
library(tidyverse)
library(ggHoriPlot)
sports <- read_tsv("./activity.tsv")
sports %>%
group_by(activity) %>%
filter(max(p) > 3e-04,
!grepl('n\\.e\\.c', activity)) %>%
arrange(time) %>%
mutate(p_peak = p / max(p),
p_smooth = (lag(p_peak) + p_peak + lead(p_peak)) / 3,
p_smooth = coalesce(p_smooth, p_peak)) %>%
ungroup() %>%
do({
rbind(.,
filter(., time == 0) %>%
mutate(time = 24*60))
}) %>%
mutate(time = ifelse(time < 3 * 60, time + 24 * 60, time)) %>%
mutate(activity = reorder(activity, p_peak, FUN=which.max)) %>%
arrange(activity) %>%
mutate(activity.f = reorder(as.character(activity), desc(activity))) -> sports
sports <- mutate(sports, time2 = time/60)
ggplot(sports, aes(time2, p_smooth)) +
geom_horizon(bandwidth=0.1) +
facet_grid(activity.f~.) +
scale_x_continuous(expand=c(0,0), breaks=seq(from = 3, to = 27, by = 3), labels = function(x) {sprintf("%02d:00", as.integer(x %% 24))}) +
viridis::scale_fill_viridis(name = "Activity relative to peak", discrete=TRUE,
labels=scales::percent(seq(0, 1, 0.1)+0.1)) +
labs(x=NULL, y=NULL, title="Peak time of day for sports and leisure",
subtitle="Number of participants throughout the day compared to peak popularity.\nNote the morning-and-evening everyday workouts, the midday hobbies,\nand the evenings/late nights out.") +
theme_ipsum_rc(grid="") +
theme(panel.spacing.y=unit(-0.05, "lines")) +
theme(strip.text.y = element_text(hjust=0, angle=360)) +
theme(axis.text.y=element_blank())library(dplyr)
library(stringr)
library(ggplot2)
library(scales)
library(ggblanket)
library(palmerpenguins)
library(patchwork)
penguins2 <- penguins |>
labelled::set_variable_labels(
bill_length_mm = "Bill length (mm)",
bill_depth_mm = "Bill depth (mm)",
flipper_length_mm = "Flipper length (mm)",
body_mass_g = "Body mass (g)",
) |>
mutate(sex = factor(sex, labels = c("Female", "Male"))) |>
tidyr::drop_na(sex)
penguins2 |>
gg_point(
x = flipper_length_mm,
y = body_mass_g,
)penguins2 |>
gg_jitter(
x = flipper_length_mm,
y = body_mass_g,
col = flipper_length_mm,
x_breaks_n = 4,
x_labels = \(x) stringr::str_sub(x, 1, 1),
y_expand_limits = 1000,
y_labels = label_number(big.mark = " "),
y_transform = "sqrt",
col_label = "Flipper\nlength (mm)",
col_steps = TRUE,
col_breaks = \(x) quantile(x, seq(0, 1, 0.25)),
col_palette = viridis::rocket(n = 9, direction = -1),
)library(ggplot2)
library(gggenes)
ggplot(example_genes, aes(xmin = start, xmax = end, y = molecule, fill = gene)) +
geom_gene_arrow() +
facet_wrap(~ molecule, scales = "free", ncol = 1) +
scale_fill_brewer(palette = "Set3")ggplot(example_genes, aes(xmin = start, xmax = end, y = molecule, fill = gene)) +
geom_gene_arrow() +
facet_wrap(~ molecule, scales = "free", ncol = 1) +
scale_fill_brewer(palette = "Set3") +
theme_genes()library(gggenomes)
# to inspect the example data shipped with gggenomes
# data(package="gggenomes")
gggenomes(
genes = emale_genes, seqs = emale_seqs, links = emale_ava,
feats = list(emale_tirs, ngaros=emale_ngaros, gc=emale_gc)) |>
add_sublinks(emale_prot_ava) |>
sync() + # synchronize genome directions based on links
geom_feat(position="identity", size=6) +
geom_seq() +
geom_link(data=links(2)) +
geom_bin_label() +
geom_gene(aes(fill=name)) +
geom_gene_tag(aes(label=name), nudge_y=0.1, check_overlap = TRUE) +
geom_feat(data=feats(ngaros), alpha=.3, size=10, position="identity") +
geom_feat_note(aes(label="Ngaro-transposon"), data=feats(ngaros),
nudge_y=.1, vjust=0) +
geom_wiggle(aes(z=score, linetype="GC-content"), feats(gc),
fill="lavenderblush4", position=position_nudge(y=-.2), height = .2) +
scale_fill_brewer("Genes", palette="Dark2", na.value="cornsilk3")library(tidyverse)
library(ggHoriPlot)
library(ggthemes)
utils::data(climate_CPH)
cutpoints <- climate_CPH %>%
mutate(
outlier = between(
AvgTemperature,
quantile(AvgTemperature, 0.25, na.rm=T)-
1.5*IQR(AvgTemperature, na.rm=T),
quantile(AvgTemperature, 0.75, na.rm=T)+
1.5*IQR(AvgTemperature, na.rm=T))) %>%
filter(outlier)
ori <- sum(range(cutpoints$AvgTemperature))/2
sca <- seq(range(cutpoints$AvgTemperature)[1],
range(cutpoints$AvgTemperature)[2],
length.out = 7)[-4]
round(ori, 2) # The origin[1] 6.58
#> [1] 6.58
round(sca, 2) # The horizon scale cutpoints[1] -12.11 -5.88 0.35 12.81 19.05 25.28
climate_CPH %>% ggplot() +
geom_horizon(aes(date_mine,
AvgTemperature,
fill = ..Cutpoints..),
origin = ori, horizonscale = sca) +
scale_fill_hcl(palette = 'RdBu', reverse = T) +
facet_grid(Year~.) +
theme_few() +
theme(
panel.spacing.y=unit(0, "lines"),
strip.text.y = element_text(size = 7, angle = 0, hjust = 0),
axis.text.y = element_blank(),
axis.title.y = element_blank(),
axis.ticks.y = element_blank(),
panel.border = element_blank()
) +
scale_x_date(expand=c(0,0),
date_breaks = "1 month",
date_labels = "%b") +
xlab('Date') +
ggtitle('Average daily temperature in Copenhagen',
'from 1995 to 2019')library(ggh4x)
utils::data(climate_US)
climate_US %>%
ggplot() +
geom_horizon(aes(date_mine,
AvgTemperature), rm.outliers = T) +
scale_fill_hcl(palette = 'RdBu', reverse = T) +
facet_nested(State+City~.) +
theme_bw() +
theme(
panel.spacing.y=unit(0, "lines"),
strip.text.y = element_text(size = 4, angle = 0),
legend.position = 'none',
axis.text.y = element_blank(),
axis.title.y = element_blank(),
axis.ticks.y = element_blank(),
panel.border = element_blank(),panel.grid = element_blank()
) +
scale_x_date(expand=c(0,0), date_breaks = "1 month", date_labels = "%b") +
xlab('Date') +
ggtitle('Average daily temperature of major US cities',
'for the year 2000')library(ggpubr)
# Load data
data("ToothGrowth")
df <- ToothGrowth
head(df, 4) len supp dose
1 4.2 VC 0.5
2 11.5 VC 0.5
3 7.3 VC 0.5
4 5.8 VC 0.5
# Box plots with jittered points
# :::::::::::::::::::::::::::::::::::::::::::::::::::
# Change outline colors by groups: dose
# Use custom color palette
# Add jitter points and change the shape by groups
p <- ggboxplot(df, x = "dose", y = "len",
color = "dose", palette =c("#00AFBB", "#E7B800", "#FC4E07"),
add = "jitter", shape = "dose")
p # Add p-values comparing groups
# Specify the comparisons you want
my_comparisons <- list( c("0.5", "1"), c("1", "2"), c("0.5", "2") )
p + stat_compare_means(comparisons = my_comparisons)+ # Add pairwise comparisons p-value
stat_compare_means(label.y = 50) # Add global p-valuelibrary(ggplot2)
# step-1
model <- lm(mpg ~ factor(cyl) * wt, data = mtcars)
# step-2
results <- fortify(model)
# step-3
ggplot(results) +
geom_point(aes(x = wt, y = mpg, color = `factor(cyl)`)) +
geom_line(aes(x = wt, y = .fitted, color = `factor(cyl)`)) +
theme_bw()library(smplot2)
ggplot(data = mpg, mapping = aes(x = displ, y = hwy, color = class)) +
geom_point() +
sm_hvgrid()unique_classes <- unique(mpg$class)
number_of_classes <- length(unique_classes)
ggplot(data = mpg, mapping = aes(x = displ, y = hwy, color = class)) +
geom_point(size = 2) +
scale_color_manual(values = sm_palette(number_of_classes)) +
sm_hvgrid()set.seed(211) # generate random data
group1 <- abs(rnorm(20, 2.5, 1))
group2 <- abs(rnorm(20, 5, 1))
Subject <- rep(paste0("S", seq(1:20)), 2)
Data <- data.frame(Value = matrix(c(group1, group2), ncol = 1))
Group <- rep(c("Group 1", "Group 2"), each = length(group1))
df <- cbind(Subject, Data, Group)
ggplot(data = df, mapping = aes(x = Group, y = Value, fill = Group)) +
sm_raincloud() +
scale_fill_manual(values = sm_color("blue", "orange"))ggplot(data = df, mapping = aes(x = Group, y = Value, fill = Group)) +
sm_raincloud() +
scale_fill_manual(values = sm_color("darkred", "viridian"))ggplot(data = df, mapping = aes(x = Group, y = Value, fill = Group)) +
sm_raincloud(boxplot.params = list(outlier.shape = NA)) +
scale_fill_manual(values = sm_color("darkred", "viridian"))library(ButterflyColors)
names(butterfly_species) [1] "philaethria_dido" "anteos_menippe"
[3] "fountainea_ryphea" "lycorea_hallia"
[5] "morpho_helenor" "archaeoprepona_demophon_thalpius"
[7] "brassolis_sophorae" "historis_acheronta"
[9] "stalachtis_phlegia_susanna" "battus_polydamas"
[11] "anteos_clorinde" "chorinea_licursis"
[13] "danaus_eresimus" "smyrna_blomfidiana"
[15] "astraptes_fulgerator" "hamadryas_feronia"
[17] "pseudolycaena_marsyas" "catagramma_pygas"
[19] "heliconius_sara_apseudes" "synargis_calyce"
[21] "hamadryas_feronia" "heliconius_erato_phyllis"
[23] "hylephila_phyleus" "danaus_erippus"
[25] "danaus_gilippus" "junonia_evarete"
[27] "hemiargus_hanno" "dynamine_postverta"
[29] "parides_zacynthus_polymetus" "marpesia_petreus"
library(ggplot2)
ggplot(iris, aes(x = Sepal.Length, y = Petal.Length, colour = Species)) +
geom_point(size = 3) +
scale_colour_manual(values = butterfly_palettes("parides_zacynthus_polymetus")) +
theme_bw()library(ggplot2)
ggplot(mpg,aes(displ, hwy)) + geom_point() +
theme_bw()ggplot(mpg,aes(displ, hwy, colour = class)) +
geom_point() +
theme_bw()ggplot(mpg, aes(displ, hwy, colour = drv)) +
geom_point() +
theme_bw()butterfly_species <- list(
philaethria_dido = c("#000000","#453E2D","#9EB5A2","#492B20","#4D4238"),
anteos_menippe = c("#A8BFAA", "#D9AD29", "#D97D0D", "#D96C0D", "#0D0D0D"),
fountainea_ryphea = c("#8C2B3D", "#2F182A", "#BF4124", "#51151F", "#43211F"),
lycorea_hallia = c("#BDC0B7", "#BF964B", "#BF6D24", "#A65221", "#260F0D"),
morpho_helenor = c("#4590BF", "#79BED9", "#6CCED9", "#A65C41", "#0D0D0D"),
archaeoprepona_demophon_thalpius = c("#3C36D9", "#322EA6", "#25B8D9", "#39BFB2", "#4C2E23"),
brassolis_sophorae = c("#714E3B", "#D3AA6A", "#AC895F", "#AD7F5D", "#936950"),
historis_acheronta = c("#9F8E7A", "#A8A9A4", "#BF5B21", "#8C2F1B", "#37231C"),
stalachtis_phlegia_susanna = c("#A3A9A9", "#BF601C", "#99401E", "#291811", "#4A2E23"),
battus_polydamas = c("#372D21", "#A67538", "#D99A4E", "#593827", "#221713"),
anteos_clorinde = c("#784116", "#9CB6A9", "#ACCFCB", "#A8BE74", "#BF7417"),
chorinea_licursis = c("#A62631", "#BF364F", "#272A59", "#373248", "#1B1613"),
danaus_eresimus = c("#C0C9CE", "#BF7839", "#A65C32", "#8C4830", "#422622"),
smyrna_blomfidiana = c("#D9B97E", "#BF5B21", "#A64521", "#8C331F", "#261915"),
astraptes_fulgerator = c("#449DB3", "#A3BAC2", "#60BFAE", "#8C6E5D", "#6C5043"),
hamadryas_feronia = c("#B7957C", "#A68A7B", "#734939", "#A6432D", "#9BA8AE"),
pseudolycaena_marsyas = c("#89B7CF", "#5C92B4", "#619FA2", "#8C6751", "#593527"),
catagramma_pygas = c("#BF2A37","#59352D", "#D3392F","#BFA77A", "#D93636"),
heliconius_sara_apseudes = c("#1F5373", "#243C56", "#CCD99C", "#B9BF8E", "#261514"),
synargis_calyce = c("#D3D9D9", "#BF7F5A", "#A65233", "#8C5946", "#5F3121"),
hamadryas_feronia = c("#A6ACAA", "#6D3E34", "#658290", "#735A4C", "#372C26"),
heliconius_erato_phyllis = c("#3D2F26", "#C1D9A9", "#A6381F", "#261A17", "#732119"),
hylephila_phyleus = c("#BB9F89", "#D98E32", "#BF7330", "#A6592D", "#733D29"),
danaus_erippus = c("#C0C0B4", "#AC522D", "#8F4E2E", "#732F20", "#402721"),
danaus_gilippus = c("#D2D4C9", "#D9843B", "#BF6734", "#A64B29", "#4B3329"),
junonia_evarete = c("#6A6758", "#A68160", "#D96F32", "#BF522A", "#734432"),
hemiargus_hanno = c("#9693A4", "#84808F", "#878CA2", "#757388", "#625A67"),
dynamine_postverta = c("#8CA48A", "#909486", "#85A68D", "#575945", "#403128"),
parides_zacynthus_polymetus = c("#37738D", "#9B8170", "#D98B79", "#BF6860", "#292325"),
marpesia_petreus = c("#D98B48", "#BC5918", "#BF4B21", "#8C311C", "#5F291C"))
ggplot(mpg, aes(displ, hwy, colour = drv)) +
geom_point() +
scale_colour_manual(values = butterfly_species$anteos_menippe) +
theme_bw()