【问题标题】:How to change the shape of dot in geom_dotplot in R?如何更改 R 中 geom_dotplot 中点的形状?
【发布时间】:2019-10-21 10:29:43
【问题描述】:

在处理ggplot()+geom_dotplot()时,想知道如何将实心点改为实心正方形

【问题讨论】:

  • 来自?geom_dotplot: "'geom_dotplot()' 理解以下美学... 'x', 'y', 'alpha', 'color', 'fill', '组'”。看来如果要改变形状,可能需要写一个新函数。

标签: r shapes dot


【解决方案1】:

欢迎来到stackoverflow。这是一个完全的黑客,但它会做你想做的事

# plot just the dotplot
p <-
  ggplot(mtcars, aes(x = mpg)) + 
  geom_dotplot(binwidth = 1.5, dotsize = 1) +
  ylim(-0.1, 1.1)


# this is the "instructions" of the plot
gpb <- ggplot_build(p)


# gpb$data is a list, you need to use the first element
gpb$data[[1]] %>% 
  ggplot(aes(x, stackpos/max(stackpos))) +
  geom_point(shape = 22, size = 14, fill = "blue") +
  ylim(-0.1, 1.1)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-29
    相关资源
    最近更新 更多