I am working with the R programming language.
I am following this link over here (
I tried to install the required library and then run the code to produce this plot:
install.packages("mosaic")
library(mosaic)
contour_plot(
sin(2*pi*t/10)*exp(-.2*x) ~ t & x,
domain(t = range(0,20), x = range(0,10)))
But this produces the following error:
Error in contour_plot(sin(2 * pi * t/10) * exp(-0.2 * x) ~ t & x, domain(t = range(0, :
could not find function "contour_plot"
I tried to re-install this package a few times, but the error keeps persisting.
Can someone please show me how to fix this?
Thanks!
sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 22000)
Matrix products: default
locale:
[1] LC_COLLATE=English_Canada.1252 LC_CTYPE=English_Canada.1252
[3] LC_MONETARY=English_Canada.1252 LC_NUMERIC=C
[5] LC_TIME=English_Canada.1252
attached base packages:
[1] splines stats graphics grDevices utils datasets methods base
other attached packages:
[1] mosaicModel_0.3.0 mosaicCalc_0.5.1 mosaicCore_0.9.0 mosaic_1.8.3 ggridges_0.5.3
[6] mosaicData_0.20.2 ggformula_0.10.1 ggstance_0.3.5 dplyr_1.0.6 Matrix_1.2-18
[11] ggplot2_3.3.5 lattice_0.20-41
loaded via a namespace (and not attached):
[1] ggrepel_0.9.1 Rcpp_1.0.7 tidyr_1.1.3 prettyunits_1.1.1 ps_1.5.0
[6] rprojroot_2.0.2 assertthat_0.2.1 digest_0.6.27 utf8_1.1.4 ggforce_0.3.3
[11] R6_2.5.0 plyr_1.8.6 backports_1.2.1 labelled_2.9.0 pillar_1.6.1
[16] rlang_0.4.10 lazyeval_0.2.2 curl_4.3 rstudioapi_0.13 callr_3.7.0
[21] readr_1.4.0 stringr_1.4.0 htmlwidgets_1.5.3 polyclip_1.10-0 munsell_0.5.0
[26] broom_0.7.6 compiler_4.0.3 pkgconfig_2.0.3 pkgbuild_1.2.0 htmltools_0.5.1.1
[31] tidyselect_1.1.0 tibble_3.1.2 gridExtra_2.3 fansi_0.4.2 crayon_1.3.4
[36] withr_2.4.1 MASS_7.3-53 grid_4.0.3 gtable_0.3.0 lifecycle_1.0.0
[41] DBI_1.1.1 magrittr_2.0.1 scales_1.1.1 cli_2.5.0 stringi_1.5.3
[46] farver_2.0.3 remotes_2.4.0 leaflet_2.0.4.1 ellipsis_0.3.2 ggdendro_0.1.23
[51] generics_0.1.0 vctrs_0.3.8 tools_4.0.3 forcats_0.5.1 glue_1.4.2
[56] tweenr_1.0.1 purrr_0.3.4 hms_1.0.0 crosstalk_1.1.1 processx_3.5.2
[61] yaml_2.2.1 colorspace_2.0-0 haven_2.4.3
CodePudding user response:
The function contour_plot
is only included in the Development version of mosaicCalc
. You can try to install it using
remotes::install_github("ProjectMOSAIC/mosaicCalc", ref="beta")
See also this issue on their github-page.
CodePudding user response:
Are you missing loading the library after installing the package?
library("mosaic")
CodePudding user response:
You can write your own version of contour_plot
with the same functionality with CRAN-based packages:
library(geomtextpath)
#> Loading required package: ggplot2
library(hrbrthemes)
contour_plot <- function(f, xlim = c(-1, 1), ylim = c(-1, 1)) {
xvals <- seq(xlim[1], xlim[2], length.out = 500)
yvals <- seq(ylim[1], ylim[2], length.out = 500)
df <- expand.grid(x = xvals, y = yvals)
df$z <- f(df$x, df$y)
ggplot(df, aes(x, y, z = z))
geom_contour_filled(alpha = 0.3)
geom_textcontour(hjust = 0.75)
theme_ipsum()
}
The first argument needs to be a function of two vectors:
contour_plot(f = function(x, y) { sin(2 * pi * x / 10) * exp(-.2 * y) },
ylim = c(0, 10),
xlim = c(0, 20))
Created on 2022-03-09 by the reprex package (v2.0.1)