六个不带图例的可变线图 [英] Six Variable Line Graph Without a Legend

查看:64
本文介绍了六个不带图例的可变线图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望复制这篇文章中看到的第一个情节的设计:

I'm looking to replicate the design of the first plot seen in this post:

http://stats.blogoverflow.com/2011/12/andyw-says-small-multiples-are-the-most-underused-data-visualization/

这是从[1]中摘录的,但是在那本书中没有显示该图的代码.

This was taken from [1], but in that book there is no code shown for the figure.

链接中的该图没有图例,而是显示标签"IN","MO"等.以交错的方式位于它们所代表的各行的高度处.我知道如何使用ggplot2进行绘图,但是我遇到的具体问题是编写代码以使标签位于图的右侧.有人可以演示如何做到这一点吗?

This figure in the link has no legend, and instead shows the labels 'IN', 'MO', ect. in a staggered fashion positioned at the height of the respective line they represent. I know how to make plots using ggplot2, but the specific issue I'm having is writing code to make the labels on the right side of the figure like that. Could someone demonstrate how to do this?

1:卡尔,丹尼尔和安培;琳达·泡椒. 2009.使用微图可视化数据模式.佛罗里达州Boca Rotan. CRC出版社.

1: Carr, Daniel & Linda Pickle. 2009. Visualizing Data Patterns with Micromaps. Boca Rotan, FL. CRC Press.

推荐答案

您可以将geom_labelnudge_x参数一起使用,如下所示:

You can use geom_label with the nudge_x argument like this:

library(data.table) # I always use data.table but not required
library(ggplot2)

a <- c(1:10)
b <- c(seq(1,20,2))
c <- c(seq(1,30,3))
d <- c(1:10)

aa <- data.table(a,b,c,d)

ggplot(aa)+
  geom_line(aes(a,b))+
  geom_line(aes(a,c))+
  geom_line(aes(a,d))+
  geom_label(aes(10,10), label = "line 1", nudge_x = 1)+
  geom_label(aes(10,19), label = "line 2", nudge_x = 1)+
  geom_label(aes(10,29), label = "line 3", nudge_x = 1)

您可以直接输入与标签所需位置相对应的有序对.情节看起来像这样:

You can directly input the ordered pair that corresponds to the desired location of your label. The plot looks like this:

这篇关于六个不带图例的可变线图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆