plotRGB error when calling plot_map() in rayshader package in R - r

I'm trying to use the rayshader package in R to plot elevation data, but I'm getting an error when I call the plot_map() function. I can't even get the example to run without running into the following error. Any ideas on how to get this function to run?
error in evaluating the argument 'x' in selecting a method for function 'plotRGB': unused argument (asp = 1)
Here is the example code that I am calling.
library(rayshader)
#Here, I load a map with the raster package.
loadzip = tempfile()
download.file("https://tylermw.com/data/dem_01.tif.zip", loadzip)
localtif = raster::raster(unzip(loadzip, "dem_01.tif"))
unlink(loadzip)
#And convert it to a matrix:
elmat = raster_to_matrix(localtif)
#We use another one of rayshader's built-in textures:
elmat %>%
sphere_shade(texture = "desert") %>%
plot_map()

Related

ggmosaic: "Discrete value supplied to continuous scale" error when ggplot2/ggmosaic is imported

In my package, I like to create a mosaic plot. In the interactive session, this works well. However, if I call the function from an fresh R session with devtools::load_all, the error "Discrete value supplied to continuous scale" is raised.
Here is a minimum working example:
test_ggmosaic <- function(dat) {
dat <- datasets::mtcars
p <- ggplot2::ggplot(data=dat)+
ggmosaic::geom_mosaic(
ggplot2::aes(weight=mpg,x=ggmosaic::product(gear, cyl), fill=mpg)
) +
ggplot2::theme_bw()+
ggplot2::scale_fill_discrete(guide=ggplot2::guide_legend(reverse=TRUE)
)
return(p)
}
Now when this function is defined inside a package, and ggplot2 and ggmosaic are added to the Imports field in the DESCRIPTION file, and I call this function after loading devtools and (via load_all) the package the function is in, I get the error
Fehler: Discrete value supplied to continuous scale
When, on the other hand, I first execute
library(ggplot2)
library(ggmosaic)
and then call the function above, the plot appears (and does not make much sense in this example).

Constant error when using the plot_time_series() function

I am trying to plot a graph using the plot_time_series function and keep on getting the following error
> Retail %>%
+ plot_time_series(Date, Profit, .interactive = F)
Error: Problem with `mutate()` input `.value_smooth`.
x No method for class character.
i Input `.value_smooth` is `auto_smooth(...)`.
Any suggestions? I tried uninstalling the timetk package but that didn't work.

Using pcaCoda from the package "robCompositions" with ggplot2

I would like to plot the results of the robust PCA (pcaCoDa) from the robCompositions package using ggplot2.
Previously, it worked with ggbiplot (https://github.com/vqv/ggbiplot) however, I can no longer get it to work with my current R version (3.6.0).
Is there a way to do a biplot with the pcaCoda results with ggplot2 using CRAN packages?
Here is a working example without using ggplot:
library(robCompositions)
df <- arcticLake
a <- pcaCoDa(df)
biplot(a)
And another example without using the robust PCA, but using the autoplot function:
library(ggplot2)
autoplot(princomp(df))
However, I would like to use the robust PCA with ggplot/autoplot. When I try to plot it, i get the following error:
autoplot(a)
Error: Objects of type pcaCoDa not supported by autoplot.
I also tried the following and also get an error:
autoplot(a$princompOutputClr)
Error in scale.default(data, center = FALSE, scale = 1/scale) :
length of 'scale' must equal the number of columns of 'x'
Any advice? Thanks!
For some reasons that I ignore pcaCoda returns one value less for scale and center compared to the output of other pca methods such as prcomp or princomp. I think that's the reason why autoplot does not want to plot this object.
Alternatively, if you want to apply the robust algortithm, you can use the package pcaMethods available on bioconductor, here i provided an example using the iris dataset that you can found on the documentation of pcaMethods (https://bioconductor.org/packages/release/bioc/html/pcaMethods.html):
if (!requireNamespace("BiocManager", quietly = TRUE))
install.packages("BiocManager")
BiocManager::install("pcaMethods")
library(pcaMethods)
library(ggplot2)
robust = pca(iris[c(1, 2, 3, 4)], method = "robustPca", scale = "uv", center = TRUE)
iris = merge(iris, scores(robust), by =0)
ggplot(iris, aes( x= PC1, y = PC2, colour = Species))+
geom_point()+
stat_ellipse()
Does it look what you are trying to get ?

autoplot does not accept ts object

I am creating a ts object and then I am trying to run it through autoplot. Execution gives me an error:
autoplot(pts, facets = TRUE)
Error: Objects of type mts/ts/matrix not supported by autoplot.
I have already checked the type of the object , and it is ts and autoplot is supposed to make a plot out of the ts object. I also tried to run other built in ts object (USAccDeaths) , but it gives me same error
library(ggplot2)
pts <- ts(data = Popcopys[,-1], start = c(2006,1),frequency = 1 )
autoplot(pts)
autoplot(USAccDeaths)
A plot of TS is expected , but what I get is this error:
autoplot(pts)
Error: Objects of type mts/ts/matrix not supported by autoplot.
autoplot(USAccDeaths)
Error: Objects of type ts not supported by autoplot.
This works:
library(ggplot2)
library(ggfortify)
autoplot(USAccDeaths)
Following https://cran.r-project.org/web/packages/ggfortify/vignettes/plot_ts.html :
"{ggfortify} lets {ggplot2} know how to interpret ts objects"
If you have ggplot or tidyverse loaded into your environment along with the forecast library both have an autoplot function.
You will need to specify which you are attempting to use.
library(forecast)
library(ggplot2)
data <-read.csv('C:/users/person/desktop/data.csv')
ts_df <-ts(data, start = 2018, frequency = 52)
forecast::autoplot(ts_df[,'Column_name'])

How can I create multiple graphs with plotly on RStudio

I am using Plotly package on RStudio. I try to use the function windows() that pops up a new window where the plot should be inserted. This function works well with the normal R function plot, ggplot... but it is not working with plotly graphs.
Here is my code:
windows()
p <- as.doubleplot_ly(data = prices_st, y = prices_st$values, group = prices_st$ind) %>%
layout(showlegend = FALSE)
And the error message is
Error: (list) object cannot be coerced to type 'double'

Resources