本文介绍了R图:创建Tufte的水平条线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何在R中复制Tufte的隐式水平线?



例如,以下是一个很好的起点:

  library(ggplot2)
ggplot(msleep,aes(x = order))+ stat_bin()+ theme_bw()

删除边框线应该很简单。关键的一点是,用横杠覆盖水平线,我不清楚。



我想这里有两种方法:


  1. 针对此特定示例的特别解决方案
  2. 建议如何将其合并到主题中


解决方案

@Andrie答案不是很大的补充,但是您可以利用包$ ggthemes 用 ggplot2 制作Tufte-sque图。下面,我使用 theme_tufte ,使用 extrafont 包更改字体,并使用 opts 来微调所有其他的视觉功能:

  library(ggthemes)
library (extrafont)
ggplot(msleep,aes(x = order))+ stat_bin(width = 0.6,fill =gray)+
theme_tufte(base_family =GillSans,base_size = 16,ticks = F)+
主题(axis.line = element_blank(),axis.text.x = element_blank(),
axis.title = element_blank())+
geom_hline(yintercept = seq 5,20,5),col =white,lwd = 1.2)

How can we replicate Tufte's implicit horizontal lines in R?

For example, the following is a good starting point:

library(ggplot2)    
ggplot(msleep, aes(x=order)) + stat_bin() + theme_bw()

Removing the border line should be straightforward. The crucial point, overlaying the horizontal line with the bars, is unclear to me.

I imagine two approaches here:

  1. Ad-hoc solution for this particular example
  2. Suggestion how to incorporate it into a theme
解决方案

Not a big addition to @Andrie answer, but you can take an advantage of the package ggthemes to make Tufte-sque plots with ggplot2. Below, I'm using theme_tufte, change the font using extrafont package, and use opts to fine-tune all the other visual features:

library(ggthemes)
library(extrafont)
ggplot(msleep, aes(x=order)) + stat_bin(width=0.6, fill="gray") + 
  theme_tufte(base_family="GillSans", base_size=16, ticks=F) +
  theme(axis.line=element_blank(), axis.text.x=element_blank(),
        axis.title=element_blank()) +
  geom_hline(yintercept=seq(5, 20, 5), col="white", lwd=1.2)

这篇关于R图:创建Tufte的水平条线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 03:58