r - 如何扩展x轴和y轴并缩小ggthemes::theme_tufte()中的间隙

标签 r ggplot2

我有以下几点:


library(tidyverse)
#> + ggplot2 2.2.1.9000        Date: 2017-06-23
#> + tibble  1.3.3                R: 3.3.2
#> + tidyr   0.6.3              GUI: X11
#> + readr   1.1.1           Locale: en_US.UTF-8
#> + purrr   0.2.2.2             TZ: Asia/Tokyo
#> + dplyr   0.7.0           
#> + stringr 1.2.0
#> Conflicts -----------------------------------------------------------------
#> * filter(),  from dplyr, masks stats::filter()
#> * lag(),     from dplyr, masks stats::lag()
tbl <- structure(list(sample = c("Fx", "Vx"), nof_degs = c(6038L, 
3606L)), .Names = c("sample", "nof_degs"), class = c("tbl_df", 
"tbl", "data.frame"), row.names = c(NA, -2L))

tbl
#> # A tibble: 2 x 2
#>   sample nof_degs
#>    <chr>    <int>
#> 1     Fx     6038
#> 2     Vx     3606

使用以下代码:

library(ggthemes)
ggplot(tbl, aes(x=sample,y=nof_degs)) +
geom_histogram(position=position_dodge(0.01), colour="black", stat="identity", width=0.2) +
  geom_rangeframe() + 
  theme_tufte() +
  theme(axis.ticks.length = unit(7, "pt"))

如下图所示:

enter image description here

最佳答案

让我知道这是否足够接近:

ggplot(df, aes(x=sample,y=nof_degs)) +
  geom_histogram(position=position_dodge(0.01), colour="black",
                 stat="identity", width=0.8) +
  geom_rangeframe(y=c(0, max(df$nof_degs))) + 
  theme_tufte() +
  theme(axis.ticks.length = unit(5, "pt"))

enter image description here

另一个选项是aspect.ratio:
ggplot(df, aes(x=sample,y=nof_degs)) +
  geom_histogram(position=position_dodge(2), colour="black",
                 stat="identity", width = 0.6) +
  geom_rangeframe(y=c(0, max(df$nof_degs))) + 
  theme_tufte() +
  theme(aspect.ratio = 2) +
  theme(axis.ticks.length = unit(5, "pt"))

enter image description here

您可以使用widthaspect.ratio参数来获得所需的图。例如width = 0.8aspect.ratio = 1.5:

enter image description here

关于r - 如何扩展x轴和y轴并缩小ggthemes::theme_tufte()中的间隙,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44716352/

相关文章:

将信息分布在多个 View 中进行检索

r - tidyverse 未加载,显示 "namespace ‘vctrs’ 0.2.0 已加载,但需要 >= 0.2.1”

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

r - 当ggplotly与facet_wrap一起使用时,仅出现第一个facet的数据

r - 自定义ggplot中y轴标签的顺序

r - 将通知链接到 shinydashboard 中的选项卡

r - 计算一个列表中出现在另一个列表中的元素数量

r - 使用结果 ='asis' 以编程方式插入 header 并使用 R markdown 在同一代码块中绘制

r - 如何在ggplot中将每一天添加为x轴标签

r - 为 geom_bar 分配连续的填充颜色