-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ordering on bar chart changes from RStudio viewer to HTML #7
Comments
library(rcdimple)
library(magrittr)
testdata <- data.frame(Precinct = structure(1:18, .Label = c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18"),
class = c("ordered", "factor")), value = c(2, 2, 3, 1, 1, 1, 0, 3, 1, 4, 2, 0, 5, 6, 4, 7, 8, 7))
dimple(data = testdata, x ="Precinct", y = "value", type = "bar") %>%
xAxis( orderRule = rev(levels(testdata$Precinct)) ) %>%
default_colors(list("#8B0000")) %>%
add_title( html = "<h2>My test data</h2>" ) Alternately, if you wanted to sort by the value, you can do this. library(rcdimple)
library(magrittr)
testdata <- data.frame(Precinct = structure(1:18, .Label = c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18"),
class = c("ordered", "factor")), value = c(2, 2, 3, 1, 1, 1, 0, 3, 1, 4, 2, 0, 5, 6, 4, 7, 8, 7))
dimple(data = testdata, x ="Precinct", y = "value", type = "bar") %>%
xAxis( orderRule = "value" ) %>%
default_colors(list("#8B0000")) %>%
add_title( html = "<h2>My test data</h2>" ) |
OK thanks. |
Hi just FYI I tried to do a grouped barchart with the group column by year and the years appeared in a random order - nothing I could figure out to make the years appear in order with a chart such as mydataframe %>% so I ended up having to use another library. |
@smach |
Thanks @happyshows. I was preparing this as I saw your answer. Maybe, something like this? library(rcdimple)
library(pipeR)
data.frame(
"year" = rep(2000:2005,each = 12)
,"month" = rep(1:12,12)
,"value" = runif( 12 * 12, 80, 100 )
) %>>%
dimple(
x = c("month","year")
,y = "value"
,groups = "year"
,type = "bar"
) %>>%
xAxis( grouporderRule = "year" ) |
That did the trick, thanks! |
With this test data frame:
If I create a bar chart with this code
the bar chart in RStudio's viewer is ordered by Precinct. However, the same graph embedded in an HTML RMarkdown document or viewed in my default browser with RStudio's "show in new window" option is ordered by descending value. The behavior probably ought to be consistent.
The text was updated successfully, but these errors were encountered: