Log scale and limits with ggvis

Hi, I am a bit confused about the scale in ggvis. I am trying to do two things: one has a log scale (equivalent to log = "x" in plot ()). I am also looking for the equivalent of xlim = c (). In both cases, the code below does not give the expected results.

# install.packages("ggvis", dependencies = TRUE) library(ggvis) df <- data.frame(a=c(1, 2, 3, 1000, 10000), b=c(0.1069, 0.0278, 0.0860, 15.5640, 30.1745)) df %>% ggvis(~a, ~b) df %>% ggvis(~a, ~b) %>% scale_numeric("x", trans="log") 

Note that with trans = "log" all points are located to the left of the graph, and the scale disappears.

Next, I want to limit the graph to certain values. I could multiply the data frame, but I want to have the xlim equivalent of plot ().

 df %>% ggvis(~a, ~b) %>% scale_numeric("x", trans="linear", domain=c(10, 40)) 

This gives even more compelling results, so I guess I'm wrong about what the domain does.

Thank you for your help!

+6
source share
3 answers

I ran into the same problem you were talking about.

Obviously, the ggvis developer also noticed this error. This is currently flagged as a problem. You can find this problem here: https://github.com/rstudio/ggvis/issues/230

In the context of your question:

 # install.packages("ggvis", dependencies = TRUE) library(ggvis) df <- data.frame(a=c(1, 2, 3, 1000, 10000), b=c(0.1069, 0.0278, 0.0860, 15.5640, 30.1745)) df %>% ggvis(~a, ~b) # Points will disapper df %>% ggvis(~a, ~b) %>% scale_numeric("x", trans="log") # Should work df %>% ggvis(~a, ~b) %>% scale_numeric("x", trans="log", expand=0) 

However, you may notice that after the conversion, the interval between ticks does not look uniform. But at least the dots are displayed correctly.

+3
source

I ran into the same problem and noticed that as soon as I deleted 0 data from my data (from which it is impossible to calculate log (), everything started working fine.

+1
source

This is strange, I've tried my data many times, but I can’t find the problem.

I tested it for US violence indicators (see help(USArrests) ) and it worked like a charm.

 data(USArrests) # str(USArrests) p <- USArrests %>% ggvis(~ Murder, ~ Rape) %>% layer_points() p %>% scale_numeric("y", trans = "log") 

This is not an answer, just share it with you.

0
source

Source: https://habr.com/ru/post/973243/


All Articles