简体   繁体   English

如何扩展x轴和y轴并缩小ggthemes :: theme_tufte()中的差距

[英]How to extend x-axis and y-axis and narrow the gap in ggthemes::theme_tufte()

I have the following nibble: 我有以下蚕食:


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

With the following code: 使用以下代码:

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"))

As shown in the image below: 如下图所示:

在此输入图像描述

Let me know if this is close enough: 如果这足够接近,请告诉我:

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"))

在此输入图像描述

Another option is with aspect.ratio : 另一个选项是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"))

在此输入图像描述

You can play around with width and aspect.ratio parameters to get a desired plot. 您可以使用widthaspect.ratio参数来获得所需的绘图。 For example width = 0.8 and aspect.ratio = 1.5 : 例如width = 0.8aspect.ratio = 1.5

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM