I see a lot of examples in javascript but I cannot find an example to do it in R
Here is the api link: http://api.highcharts.com/highcharts#global
I am trying to set "timezoneOffset" and I have tried many different ways.
When I do this in R: highChart$global(timezoneOffset=-300)
I do not get any warning or error, but it's not working.
Thanks a lot for the help!
Here is a piece of code:
library(rCharts)
highChart <- Highcharts$new()
highChart$global(timezoneOffset=-300)
highChart$chart(zoomType = "xy")
highChart$exporting(enabled = T)
highChart$xAxis(type="datetime",list( title = list(text = "Time")))
highChart$yAxis(list
(
list(title = list(text = "Variance"))
))
highChart$series(data=list(c(x=1407795845000,y=1),c(x=1407795846000,y=2),c(x=1407795847000,y=3)))
highChart
As you can see, the timezoneOffset is not working when I run this piece of code and the time is still displayed in GMT.
As of version 0.5.0 of highcharter, it seems the option highcharter.options is not there any more, but there are several separate options, e.g. highcharter.lang, highcharter.global, etc. So the following approach works:
lang <- getOption("highcharter.lang")
lang$decimalPoint <- ","
lang$numericSymbols <- highcharter::JS("null") # optional: remove the SI prefixes
options(highcharter.lang = lang)
In addition to changing the decimal point, the SI prefixes ("k", "M", "G", etc.) are turned off by setting the numericSymbols to null, see Replacing/removing the metric notations like thousands "k" abbreviation.
The highcharter options can be accessed, but they are set inside the standard R options under the list element highcharter.options. They are not given directly to the highchart, and inside highchart(), there is the code line opts <- getOption("highcharter.options", list()).
I don't think there is another way than just get the options, alter whatever options you need to change and then set the options again with your additions.
The following is a simple illustration:
library(highcharter)
# normal highchart
highchart() %>%
hc_add_serie_labels_values(1:901, seq(1, 10, 0.01))
opts <- getOption("highcharter.options")
opts$lang$decimalPoint <- "."
options(highcharter.options = opts)
# now with "," instead of "." (confirm in tooltip)
highchart() %>%
hc_add_serie_labels_values(1:901, seq(1, 10, 0.01))
Of course in your case, you need to set the $global$timezoneOffset part.
First you have to switch of the useUTC flag to FALSE. Than you can set the timezoneOffset as you wish and save the options back.
global <- getOption("highcharter.global")
global$useUTC <- FALSE
global$timezoneOffset <- -300
options(highcharter.global = global)
For better understanding make sure you take a look at global:
str(global)
Related
Is it possible to create a wordcloud with greek symbols? Since expression is not working within a data frame, is there a workaround?
Here is a small example what I'm trying to do, but haven't figured out how the cloud could show the symbols instead.
library(highcharter)
hchart(data.frame(greek_symbols = c("beta","mu","gamma")), "wordcloud", hcaes(name = greek_symbols, weight = rep(1,1,1)))
If youir input is given by the written names of the symbols you could make a translation vector as in your cloud you want to provide the unicode value of the symbol. symbols_conversion should include all (I just added yours plus one). So symbols_to_show contains the names you want to display. Subset like symbols_conversion[symbols_to_show] to get the symbols shown.
library(highcharter)
symbols_conversion <- c("beta" = "\u03b2", "gamma" = "\u03b3", "delta" = "\u03b4", "mu" = "\u03bc")
symbols_to_show <- c("beta","mu","gamma")
hchart(data.frame(greek_symbols = symbols_conversion[symbols_to_show]), "wordcloud", hcaes(name = greek_symbols, weight = rep(1,1,1)))
I am using nVennr, which has proved to be quite useful, although have been through all of the supporting documentation and still can't find out how to do 2 things that I am imagine are possible. They are how to change the displayed figures to non-standard-form format, and how to remove the legend.
Below is some data that illustrates how nVennr automatically converts figures to standard form.
library(nVennr)
library(dplyr)
library(rsvg)
library(grImport2)
SetA = round(runif(10000000),0)
SetB = round(runif(10000000),0)
SetC = round(runif(10000000),0)
allSets = cbind(SetA, SetB, SetC) %>%
as.data.frame() %>%
rownames_to_column()
SetA = subset(allSets, SetA == 1)$rowname
SetB = subset(allSets, SetB == 1)$rowname
SetC = subset(allSets, SetC == 1)$rowname
myV = plotVenn(list(SetA = SetA,
SetB = SetB,
SetC = SetC),
nCycles = 10000)
Any help would be greatly appreciated, in particular with the standard form issue, and this renders the plots quite ugly.
Thanks!
Glad you like the package. I am not sure what you mean by standard form. Perhaps you want one of those diagrams with three overlapping circles. In that case, I would recommend using other packages, like those suggested here. You can get a regular Venn diagram with nVennR, as shown in the vignette, but the default shape is always round in the region, not in the set:
library(nVennR)
myV3 <- createVennObj(nSets = 3, sSizes = c(rep(1, 8)))
myV3 <- plotVenn(nVennObj = myV3, labelRegions=F, showNumbers=F, opacity=0.2, borderWidth=4)
The result would be:
Regarding the legend, I did not think that would be necessary, as it is very easy to remove from the resulting svg file. However, since I need to upload a new version, I will add this function shortly.
EDIT:
The new version of nVennR (0.2.2) has just been released. Now, plotVenn and showSVG have the option showLegend. If set to false, the legend is not shown.
I'm not sure if this is the correct forum to post this, but I have noticed some strange behavior with the flextable package in R, and was wondering if anyone can shed any light.
In the documentation for flextable it shows objects being modified when they are re-assigned to themselves, eg:
ft <- regulartable(head(iris))
ft <- color(ft, color = "orange", part = "body" )
However, my code is modifying the actual table even without re-assigning it, just using piping %>%:
myft <- regulartable(head(iris))
myft %>% align(j = 1, align = "left")
myft # changed
I don't think piping is the issue as it doesn't have the same effect with other packages, eg:
library(plyr)
df <- head(iris)
df %>% mutate(Sum=Sepal.Width*2)
df # unchanged
Is this a bug in flextable? Or is this by design?
It's true that you can mutate formats without assigning the object. But that's not a behavior you can rely on. This is an unwanted design ;) and should be corrected in the next versions so it is safer to assign the result if you want your code to work with future versions.
How can I create an image from a data frame? For example:
library(tidyverse)
library(gridExtra)
df = iris %>% slice(1:4)
I've the following but:
1. I haven't been able to get this to be saved to a variable. It just pops up in the plots pane of Rstudio. Am I missing something obvious? I'd like to be able to have this plot referenced to a variable so I could save it as a png or something.
2. Is there a way to remove the row numbers that seem to appear?
3. This look is fine, but is there a way to make it more of a lighter background compared to what this is?
gridExtra::grid.table(df)
To save a relevant variable, use
myTable <- tableGrob(df)
since
grid.table
# function (...)
# grid.draw(tableGrob(...))
# <bytecode: 0x10758c078>
# <environment: namespace:gridExtra>
Given that, you can run
library(grid)
grid.draw(myTable)
For that you want
myTable <- tableGrob(df, rows = NULL)
See ?tableGrob and particularly ttheme_default (its source code makes pretty clear what are possible parameters; see also here). For instance,
myTable <- tableGrob(
df,
rows = NULL,
theme = ttheme_default(core = list(bg_params = list(fill = "grey99")))
)
grid.draw(myTable)
I have a simple dataframe I am trying to export to a word document. I am working
with ReporteRs. I want all number to be at the center of the cell (both in the body and the header).
a <- 1:5
b <- 1:5
df <- data.frame(a,b)
According to the documentation "Use ft_object[] <- value to perform the operation on the whole part (body, header or footer) of the FlexTable."
So I try
df_Flex <- FlexTable(df)
setFlexTableWidths(df_Flex, rep(0.5,2))
df_Flex[] <- parProperties(text.align = 'center')
Yet, the results is a table with only the number in the body being at
the center. The header is not. If I want both the header and the body to be at the center I have to write two lines of code
df_Flex[] <- parProperties(text.align = 'center')
df_Flex[,,to='header'] <- parProperties(text.align = 'center')
which is annoying because if I want to perform other formatting I will need
to write the code twice each time.
Does anyone know why this happens and how to solve the problem?
Use the functions provided in the flextable package itself, rather than in reporteRs, as these provide a much simpler interface for modifying the body and header parameters. An example using the pipe operator from magrittr or dplyr:
df_Flex2 =
regulartable(df) %>%
width(width = c(0.5, 2)) %>%
align(align = "center", part = "all")
Edit: Formatting decimal places
To control the number of decimal places shown for non-integer values in a regulartable use the set_formatter function with custom formatting for each column you want to display with different decimal places:
df_Flex2 =
regulartable(df) %>%
set_formatter(a = function(x) sprintf("%.1f", x),
b = function(x) sprintf("%.1f", x)) %>%
width(width = c(0.5, 2)) %>%
align(align = "center", part = "all")
df_Flex2
Output:
If you don't want to name individual columns you can set a revised default for numeric double types by using set_formatter_type in place of set_formatter. This example sets the number of decimal places for doubles in the regulartable to 1 decimal place in a piped expression:
set_formatter_type(fmt_double = "%.1f")
If not used with the pipe (%>%) you'd need to supply the name of the regulartable variable as the first argument:
set_formatter_type(df_Flex2, fmt_double = "%.1f")