2017-06-23 17 views
10

Tôi có nibble sau:Làm thế nào để mở rộng trục x và trục y và thu hẹp khoảng cách trong ggthemes :: theme_tufte()


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 

Với đoạn mã sau:

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

Như thể hiện trong hình dưới đây:

enter image description here

Trả lời

9

Hãy cho tôi biết nếu điều này là đủ gần:

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

lựa chọn khác là với 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

Bạn có thể chơi xung quanh với widthaspect.ratio tham số để có được một âm mưu mong muốn. Ví dụ width = 0.8aspect.ratio = 1.5:

enter image description here

+1

nhờ một triệu. Làm thế nào tôi có thể làm cho thanh mỏng hơn (25% mỏng hơn?) – neversaint

+1

giảm 'chiều rộng' để có thể' 0,6'? – AK88

+1

Tôi đã thử 'geom_histogram (position = position_dodge (0,01), color =" black ", stat =" identity ", width = 0.2)', với mã của bạn. Nó làm tăng khoảng cách một lần nữa. Tôi đã cố gắng tránh. – neversaint

Các vấn đề liên quan