Open bshor opened 7 years ago
This should be possible. Just need to drop rounding in two places:
https://github.com/leeper/slopegraph/blob/master/R/slopegraph.R#L110
https://github.com/leeper/slopegraph/blob/master/R/ggslopegraph.R#L104
@leeper may want to think about using signif rather than rounding.
@bshor I just recently added ggslopegraph2 to the package and it uses some different approaches to this problem. You're welcome to give it a try if you like. This should work for you and includes the data you provided in your example.
devtools::install_github("leeper/slopegraph")
library(slopegraph)
bshor <- structure(list(Year = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 1L,
2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L,
6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L,
4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L,
2L, 3L, 4L, 5L, 6L), .Label = c("1996", "2000", "2004", "2008",
"2014", "2017"), class = "factor"),
State = structure(c(9L, 9L, 9L, 9L, 9L, 9L, 6L, 6L, 6L, 6L, 6L, 6L, 2L, 2L, 2L, 2L, 2L, 2L,
8L, 8L, 8L, 8L, 8L, 8L, 10L, 10L, 10L, 10L, 10L, 10L, 1L, 1L,
1L, 1L, 1L, 1L, 7L, 7L, 7L, 7L, 7L, 7L, 3L, 3L, 3L, 3L, 3L, 3L,
4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L), .Label = c("CT", "MA", "MD", "ME", "NH", "NJ", "NY", "PA", "RI", "VT"), class = "factor"),
Pct = c(0.61, 0.51, 0.46, 0.51, 0.61, 0.78, 0.94, 0.95, 0.94,
0.97, 0.97, 0.98, 0.98, 0.99, 0.99, 0.97, 0.97, 0.98, 1.26,
1.23, 1.23, 1.26, 1.3, 1.4, 1.32, 1.27, 1.3, 1.13, 1.28,
1.71, 1.32, 1.36, 1.33, 1.33, 1.31, 1.33, 1.44, 1.37, 1.49,
1.38, 1.5, 1.57, 1.46, 1.7, 1.71, 1.8, 1.92, 2.07, 1.56,
1.45, 1.56, 1.57, 1.78, 1.95, 1.83, 1.79, 1.84, 1.82, 1.79,
1.71)), row.names = c(NA, -60L), class = "data.frame")
ggslopegraph2(bshor, Year, Pct, State,
title = "Display labels by fewer decimals #16",
linecolor = "light gray",
subtitle = "With defaults")
bshor$rPct <- signif(bshor$Pct, 2)
ggslopegraph2(bshor, Year, rPct, State,
title = "Display labels by fewer decimals #16",
linecolor = "light gray",
subtitle = "With signif digits = 2")
Going to give this a shot and report back!
I'd like to display slopegraphs with points with only a single decimal, so I use
decimal=1
in my specification. But if I do, I get overlap of labels (eg VT and CT below) which I wouldn't get if useddecimal=2
. But using the latter is so untidy! Is there any way to get the benefit of the latter without displaying more than one significant digit?One Significant Digit
Two Significant Digits