小编Las*_*vig的帖子

R ggrides 包绘制平均线(非中间)

我想在我的骑行图中画一条线来表示平均值。内置的分位数参数以我想要的样式画一条线,但在中位数. 我怎样才能平均绘制一个,最好不使用geom_vline()ggplot 构建对象的 pluck但留在 ggridges 生态中?

library(tidyverse)
library(ggridges)

#adding a column for the mean of each Species of the iris dataframe
iris_meaned <- iris %>%
  group_by(Species) %>% 
  mutate(mean_petal_len = mean(Petal.Length)) %>% 
  ungroup()


iris_meaned %>% 
  ggplot() +
  geom_density_ridges(
    aes(x = Petal.Length, y = Species, fill = Species), 
    quantile_lines = T, quantiles = 2 #adding lines for the median
  ) +
  geom_text(
    aes(x = mean_petal_len, y = Species, label = round(mean_petal_len, 2)),
    size = 2, nudge_x …
Run Code Online (Sandbox Code Playgroud)

r ggplot2 tidyverse ggridges

12
推荐指数
1
解决办法
520
查看次数

使用unicode字符作为形状

我想在ggplot中使用unicode字符作为绘图的形状,但由于未知原因它们不会渲染.我确实在这里找到了类似的查询,但是我也无法使这个例子工作.

任何线索为什么?

请注意,我不想将unicode字符用作"调色板",我希望绘制的每个项目geom_point()都是相同的形状(颜色将指示相关变量).

运行

Sys.setenv(LANG = "en_US.UTF-8")
Run Code Online (Sandbox Code Playgroud)

并重新启动R没有帮助.在sprintf()中包装unicode也没有用.

这是一个示例代码,用于说明问题:

library(tidyverse)
library(ggplot2)
library(Unicode)

p1 = ggplot(mtcars, aes(wt, mpg)) +
  geom_point(shape="\u25D2", colour="red", size=3) +
  geom_point(shape="\u25D3", colour="blue", size=3) + 
  theme_bw()

plot(p1)
Run Code Online (Sandbox Code Playgroud)

这就是结果.

在此输入图像描述

我使用macOS Sierra(10.13.6),R版本3.5.1和Rstudio 1.0.143.

感谢任何帮助!我一直在寻找一些寻找解决方案并发布到#Rstats的论坛,到目前为止没有任何效果.可能是解决方案隐藏在某个地方的某个线程中,但如果是这样,我就无法检测到它,我怀疑其他人也错过了它.所以,在这里,我正在制作我的第一篇文章,以堆栈溢出:)

unicode r ggplot2

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

标签 统计

ggplot2 ×2

r ×2

ggridges ×1

tidyverse ×1

unicode ×1