相关疑难解决方法(0)

如何在facet_wrap中为标签添加表达式?

我有一个数据集,我想从中绘制小的倍数,特别是在2乘2的数组中,如下所示:

mydf <- data.frame(letter = factor(rep(c("A", "B", "C", "D"), each = 20)), x = rnorm(80), y = rnorm(80))
ggplot(mydf, aes(x = x, y = y)) + geom_smooth(method = "lm") + geom_point() + facet_wrap(~ letter, ncol = 2)
Run Code Online (Sandbox Code Playgroud)

但是,我希望每个构面标签都包含一个表达式,例如

expression(paste("A or ", alpha))
Run Code Online (Sandbox Code Playgroud)

我可以使用facet_grid()via 来实现这一点

f_names <- list('A' = expression(paste("A or ", alpha)), 'B' = expression(paste("B or ", beta)), 'C' = expression(paste("C or ", gamma)), 'D' = expression(paste("D or ", delta)))
f_labeller <- function(variable, value){return(f_names[value])}
ggplot(mydf, aes(x = x, …
Run Code Online (Sandbox Code Playgroud)

r ggplot2

9
推荐指数
1
解决办法
6514
查看次数

ggplot scale_x_continuous with symbol:make bold

这是问题:我ggplot用来制作一个图表,其中x轴的范围是-90到90度.我已成功使用函数将度数符号添加到创建的刻度标签中by scale_x_continuous.但是,当我使用调整字体面时theme(),刻度标签不会变为粗体.但是,更改字体大小是有效的.这是一个可重复的例子:

# function to add degree symbols
add_degree <- function(x) {
  parse(text = paste(x, "*degree",sep = ""))
}

y<- c(0.00552243346007605, 0.00553155893536122, 0.005693536121673, 
        0.0054722433460076, 0.00562661596958175, 0.00546768060836502, 
        0.00561292775665399, 0.00550950570342205, 0.0056851711026616, 
        0.00551558935361217, 0.0055041825095057, 0.00556501901140684, 
        0.00552699619771863, 0.00552623574144487, 0.0055680608365019, 
        0.00567148288973384, 0.00550342205323194, 0.00553764258555133, 
        0.00538098859315589, 0.00573307984790875, 0.00564486692015209, 
        0.00561444866920152, 0.00556349809885932, 0.00571254752851711, 
        0.00544030418250951, 0.00557946768060837, 0.00546083650190114, 
        0.00549049429657795, 0.00557414448669202, 0.00553916349809886, 
        0.00551787072243346, 0.00557794676806084, 0.0055041825095057, 
        0.00552699619771863, 0.0056509505703422, 0.00544790874524715, 
        0.00555555555555556)

x <- seq(-90,90,by = 5)
dat <- data.frame(x,y)
ggplot(dat,aes(x = x, y = y))+
  geom_line()+
  scale_x_continuous(limits = …
Run Code Online (Sandbox Code Playgroud)

r ggplot2

6
推荐指数
2
解决办法
1868
查看次数

如何在ggplot2中使用斜体标签的斜体?

我试图在ggplot2中使用斜体名称的斜体.我首先订购并重命名方面.我遇到了一个潜在的解决方案,但这需要labeller=label_parsedlabeller=name_labeller用来重命名我的方面.

在下面的例子中,我希望facet名称"one""two""three""four"和"five"为斜体.这是一个示例数据帧:

structure(list(Names = c(1L, 1L, 2L, 2L, 3L, 3L, 4L, 4L, 5L, 
5L, 6L, 6L, 7L, 7L, 8L, 8L, 9L, 9L, 10L, 10L), Other = c(5L, 
3L, 2L, 6L, 5L, 4L, 5L, 4L, 5L, 3L, 2L, 6L, 5L, 4L, 5L, 4L, 4L, 
5L, 3L, 2L), X = c(0L, 10L, 0L, 10L, 0L, 10L, 0L, 10L, 0L, 10L, 
0L, 10L, 0L, 10L, 0L, 10L, 0L, 10L, 0L, 10L), Y = c(0L, 10L, 
0L, 10L, …
Run Code Online (Sandbox Code Playgroud)

r ggplot2

4
推荐指数
1
解决办法
4985
查看次数

标签 统计

ggplot2 ×3

r ×3