use*_*288 1 r data-visualization ggplot2
我正在绘制一些温度数据作为深度的函数.但我希望它对非科学家更友好,并明确表示顶部是水面.有关如何做到这一点的任何想法?(艺术浪潮的奖金!)
目前为止有以下几种选择:
library(dplyr); library(ggplot2); library(magrittr);
temperature <- rnorm(30, mean = 20)
depth <- seq(0:29)
df <- data.frame(temperature, depth)
no_surface <- df %>%
ggplot(aes(y = depth, x = temperature, colour = temperature)) +
geom_path(size = 2) +
scale_y_reverse() +
scale_colour_gradient(low = "blue", high = "red")+
theme_classic() +
theme(legend.position = "none")
flat_surface <- no_surface + geom_hline(yintercept = 0)
wavy_surface <- no_surface + stat_function(fun = function(x)sin(x^1.5),
size = 1)
Run Code Online (Sandbox Code Playgroud)
这个很漂亮,我眼里含着泪水:
ggplot(df, aes(xmin=1, xmax=10, ymin=-depth+1, ymax=-depth, fill=temperature)) +
annotate("text", x=7, y=1.5, label="\u2600", size = 60, color = "orange") +
geom_rect() +
geom_area(
aes(x), data.frame(x=c(1,10)), inherit.aes=F, stat="function",
fun = function(x)abs(sin(2*x))+.2, fill="blue"
) + coord_cartesian(ylim=c(-30, 10)) +
theme_minimal() + theme(axis.text.x=element_blank(), axis.ticks.x=element_blank()) +
labs(x=NULL, y="level")
Run Code Online (Sandbox Code Playgroud)