R 图:创建 Tufte 的水平条线

编程入门 行业动态 更新时间:2024-10-27 09:39:59
本文介绍了R 图:创建 Tufte 的水平条线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

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

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:

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

推荐答案

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

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 的水平条线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-01 09:40:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/826478.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:水平   Tufte

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!