小编Mat*_*sko的帖子

当plot.margin存在ggplot2时标题右对齐

我想将标题推到右侧,但包括添加的边距(右侧 30 毫米)。我找不到任何有关如何执行此操作的信息。使用plot.caption = element_text(hjust = 1)内部theme()不起作用。如果可能的话我想要纯 ggplot2 解决方案。它需要在任何绘图中工作(不同的 x 限制不仅在这个绘图中)。

library(tibble)
library(ggplot2)
library(dplyr)

tibble(x = letters[1:4], n = 10*1:4, lab = " long thus margin") %>%
  ggplot(aes(reorder(x, n), n)) +
  geom_bar(stat = "identity") +
  geom_text(aes(label = lab), hjust = -0.1) +
  coord_flip(clip = "off") +
  labs(caption = "This is caption") +
  theme_minimal() +
  theme(plot.margin = unit(c(0, 30, 0, 0), "mm"))
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

编辑:

目标是实现这个情节:

在此输入图像描述

r ggplot2

5
推荐指数
1
解决办法
1355
查看次数

像在 Excel 中一样平滑(ggplot2 + plotly)

我想使用 ggplot2 和 plotly 在 R 中模拟 Excel 平滑样式。

套餐

library(dplyr)
library(tibble)
library(ggplot2)
library(plotly)
library(ggforce) #only for geom_bspline() in example below (other smoothing functions can be used)
library(scales) #only for percent() formatting below 
Run Code Online (Sandbox Code Playgroud)

示例数据集

df <- tibble(Group = rep(LETTERS[1:2], each = 10),
             x = rep(1:10, 2),
             y = c(2, 5, 9, 15, 19, 19, 15, 9, 5, 2,
                   1, 0, 3, 2, 3, 4, 14, 24, 24, 25)*0.01)
Run Code Online (Sandbox Code Playgroud)

我想要的是

在此处输入图片说明

到目前为止我所拥有的

(df %>%
    ggplot(aes(x, y)) +
    geom_point(aes(color = Group)) +
    ggforce::geom_bspline(aes(group …
Run Code Online (Sandbox Code Playgroud)

r ggplot2 plotly

3
推荐指数
1
解决办法
912
查看次数

标签 统计

ggplot2 ×2

r ×2

plotly ×1