taucharts
taucharts copied to clipboard
Plot months in x-axis?
The ticks in this plot go from 0 to 13:
countspermonth <-
structure(
list(
month = c(4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2,
3), count = c(
1203409L, 1104115L, 933362L, 940897L, 1149347L,
1221000L, 1319375L, 1087002L, 1126721L, 1276824L, 1152835L, 1687903L
)
), row.names = c(NA,-12L), class = "data.frame", .Names = c("month",
"count")
)
library(taucharts)
tauchart(countspermonth) %>%
tau_line(x = "month", y = "count") %>%
tau_guide_x(label="Month") %>%
tau_guide_y(label="Counts", label_padding=50)
Is there a way to tell tauchart to use months instead of numbers? Or at least respect the 4,5,..2 ticks?
Thanks!
perhaps by making them actual dates?
On Wed, Aug 26, 2015 at 9:54 AM, ignacio82 [email protected] wrote:
countspermonth <- structure( list( month = c(4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3), count = c( 1203409L, 1104115L, 933362L, 940897L, 1149347L, 1221000L, 1319375L, 1087002L, 1126721L, 1276824L, 1152835L, 1687903L ) ), row.names = c(NA,-12L), class = "data.frame", .Names = c("month", "count") ) library(taucharts) tauchart(countspermonth) %>% tau_line(x = "month", y = "count") %>% tau_guide_x(label="Month") %>% tau_guide_y(label="Counts", label_padding=50)
Thanks! This this the trick:
countspermonth <-
structure(
list(
month = c(4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2,
3), count = c(
1203409L, 1104115L, 933362L, 940897L, 1149347L,
1221000L, 1319375L, 1087002L, 1126721L, 1276824L, 1152835L, 1687903L
)
), row.names = c(NA,-12L), class = "data.frame", .Names = c("month",
"count")
)
countspermonth <- countspermonth %>% mutate(month = month.abb[month])
library(taucharts)
tauchart(countspermonth) %>%
tau_line(x = "month", y = "count") %>%
tau_guide_x(label="Month") %>%
tau_guide_y(label="Counts", label_padding=50)
well, this brings up something interesting (poking @timelyportfolio to chime in if he has time, too). Why does:
countspermonth$nam <- month.abb[countspermonth$month]
tauchart(countspermonth) %>%
tau_line(x = "nam", y = "count") %>%
tau_guide_x(auto_scale=TRUE, label="Month") %>%
tau_guide_y(label="Counts", label_padding=50)

work, but:
countspermonth$onam <- factor(countspermonth$month,
levels=countspermonth$month,
labels=month.abb[countspermonth$month],
ordered=TRUE)
tauchart(countspermonth) %>%
tau_line(x = "onam", y = "count") %>%
tau_guide_x(auto_scale=TRUE, label="Month") %>%
tau_guide_y(label="Counts", label_padding=50)

not (when, IMO it should be the other way around)?
I just noticed that my months are out of order :( . Is that fixable?
Well, that's kind of the issue I just posted & reopened ;-)
On Wed, Aug 26, 2015 at 11:01 AM, ignacio82 [email protected] wrote:
I just noticed that my months are out of order :( . Is that fixable?
— Reply to this email directly or view it on GitHub https://github.com/hrbrmstr/taucharts/issues/49#issuecomment-135051327.
this works, but i can't figure out how to reduce the number of x axis ticks.
countspermonth$mon <- as.Date(sprintf("%d-%02d-01", c(rep(2013, 9),
rep(2014, 3)),
countspermonth$month))
tauchart(countspermonth) %>%
tau_line(x = "mon", y = "count") %>%
tau_guide_x(auto_scale=TRUE, label="Month", tick_format="%b", tick_period="year") %>%
tau_guide_y(label="Counts", label_padding=50)

That's probably a question for the TauCharts team.
looking at it now
(totally no rush @timelyportfolio just looping you in on an interesting issue that I think is a TauCharts issue, and not an htmlwidgets one since the data structure up until the handoff to TauCharts.JS is fine)
Guess it seems like to separate issues to me.
separate from the question posed by @ignacio82 is the auto_scale argument does not flow through in tau_guide_x.
#let's say we wanted 1 to 12 with no 0 or 1
tau <- tauchart(countspermonth) %>%
tau_line(x = "month", y = "count") %>%
tau_guide_x(label="Month", min = 1, max = 12, auto_scale = FALSE) %>%
tau_guide_y(label="Counts", label_padding=50)
tau
#get TRUE
tau$x$guide$x$autoScale
#manually set
tau$x$guide$x$autoScale = TRUE
tau
what we think is the TauCharts problem when we supply an order
@ignacio82 & @hrbrmstr
For reference, the issue is only with the tau_line probably due to the d3 line constructor. tau_bar and tau_point work as expected.
countspermonth %>%
mutate( monthorderedfactor = factor(month,ordered =T) ) %>%
tauchart() %>%
tau_bar(x = "monthorderedfactor", y = "count") %>%
tau_guide_x(label="Month") %>%
tau_guide_y(label="Counts", label_padding=50) %>%
tau_tooltip

@timelyportfolio @hrbrmstr if the dates are yearmon I get this:
countspermonth <-
structure(
list(
yearmon = structure(
c(
2014.25, 2014.33333333333,
2014.41666666667, 2014.5, 2014.58333333333, 2014.66666666667,
2014.75, 2014.83333333333, 2014.91666666667, 2015, 2015.08333333333,
2015.16666666667
), class = "yearmon"
), count = c(
2492L, 2443L,
2070L, 2999L, 2468L, 2285L, 3003L, 2467L, 3271L, 2979L, 2581L,
3601L
), requierecrt = c(
5.17656500802568, 4.25706099058535, 5.16908212560386,
5.90196732244082, 4.13290113452188, 6.17067833698031, 3.99600399600399,
7.13417105796514, 4.46346682971568, 5.27022490768715, 6.12165827198761,
6.2204943071369
)
), .Names = c("yearmon", "count", "crt"), class = "data.frame", row.names = c(NA,-12L)
)
tauchart(countspermonth) %>%
tau_line(x = "yearmon", y = "count") %>%
tau_guide_x(label="Month") %>%
tau_guide_y(label="Counts", label_padding=50) %>%
tau_tooltip() %>%
make_black_tooltip()
Is changing the x axis to just show the year and the month without the day an easy fix?