如果满足条件,我想更改 ggplot 中 x 轴文本的颜色。没问题,但为此,我必须知道theme_minimal(). 我查看了源代码,theme_bw()这让我theme_grey()找到了你可以在这里找到的源代码:https : //github.com/tidyverse/ggplot2/blob/master/R/theme-defaults.r
我看到许多声明颜色但不是其中之一x-axis?
我可以画出下面的标签df使用geom_text:
df <- data.frame(
x = c(610, 426, 569, 253),
y = c(-226, -276, -364, -185),
label = c("accomplishments per week", "hours worked per week", "perceived adequacy of accomplishments", "energy level"),
stringsAsFactors = FALSE
)
ggplot(df, aes(x, y)) + geom_text(aes(label = label))
Run Code Online (Sandbox Code Playgroud)
但是,当尝试对真实数据使用相同的绘图机制时,出现错误:
Error in FUN(X[[i]], ...) : object 'label' not found
为什么会这样,我该如何解决?
这是我的真实数据df1:
df1 <- structure(list(type = c("var", "var", "var", "var"),
id = c(1,2, 4, 7),
x = c(610, 426, …Run Code Online (Sandbox Code Playgroud) 在此输入图像描述我已经在 R 中使用某些参数构建了一个箱线图,但我不知道 xc2xb4t 代码来帮助我了解箱体的上限和下限。如果有人可以帮助我,我将不胜感激。我知道数量只是不知道上限和下限。
\n我找到了一种通过组合两个 geom_area 图来创建带有尾部区域的正态分布来“破解”ggplot的方法:
library(ggplot2)
mean <- 0
standard_deviation <- 1
Zscore <- -1.35
observation = (Zscore*standard_deviation) + mean
(tail_area <- round(pnorm(observation),2))
ggplot(NULL, aes(c(-5,5))) +
geom_area(stat = "function", fun = dnorm, fill="sky blue", xlim = c(-5, -1.35)) +
geom_area(stat = "function", fun = dnorm, xlim = c(-1.35, 5))
Run Code Online (Sandbox Code Playgroud)
是否有使用 ggplot 创建正态分布并像上面一样突出显示尾部区域的“不那么hackey”的方法?