I have a data frame named df and want to create an animated chart line.
here is my data frame and code for animating the plot.
co1<- tibble(age= c(10:14 ), pop=c(10,12,14,16,18), cn= c(10.1,12.1,14.25,16.09,18.3), country ="USA")
co2<- tibble(age= c(10:14 ), pop=c(10.5,12.6,14.5,16.5,18.5), cn= c(10.6,12.5,14.3,16.7,18.6), country ="brazil")
co3<- tibble(age= c(10:14 ), pop=c(10.9,12.9,14.9,16.9,18.9), cn= c(11.9,13.9,15.9,17.9,19.9), country ="niger")
df<- rbind(co1,co2,co3)
df <- pivot_longer(df, cols = c("pop", "cn"))
#plot
ggplot(df, aes(x = age, y = value, group = country, col = name)) + geom_line() +
labs(x = "age", y = "population") + transition_states(country, transition_length = 3, state_length = 0) +
ggtitle("country: {closest_state}") +
theme_bw()
but when I try to run the example provided, I get this error:
Error in transform_path(all_frames, states[[i]], ease, nframes[i], !!id, : transformr is required to tween paths and lines
following some questions I have tried to install package transformr and devtools::install_github("thomasp85/transformr") but both did not work and I got this error :
Warning in install.packages :
downloaded length 2292878 != reported length 3644763
Warning in install.packages :
URL 'https://cran.rstudio.com/src/contrib/sf_1.0-1.tar.gz': Timeout of 60 seconds was reached
Error in download.file(url, destfile, method, mode = "wb", ...) :
download from 'https://cran.rstudio.com/src/contrib/sf_1.0-1.tar.gz' failed
Warning in install.packages :
download of package ‘sf’ failed
The error messages indicate that there is an issue with installing the sf package. It looks like the CRAN mirror (https://cran.rstudio.com/) you are using is not responding. This might be a temporary issue.
You can try to select another mirror with chooseCRANmirror() or specify another mirror just to install the sf package:
install.packages('sf', repos='http://cran.us.r-project.org')
If that works try again to run devtools::install_github("thomasp85/transformr").
Related
I am very new to R, so apologies if I don't make any sense.
I am trying to make a flexdashboard for a class project and wanted to create an animated graph. The following code worked just fine in a regular R script, but I keep getting the error
Quitting from lines 114-156 (FInal-Project-Markdown.Rmd)
Error in switch(tolower(device), ragg_png = , png = paste0(files, ".png"), :
EXPR must be a length 1 vector
Calls: <Anonymous> ... <Anonymous> -> animate.gganim -> do.call -> <Anonymous>
I have all of the correct packages downloaded, and I made sure to load the data frames into the markdown file. As I said, I am quite new to R, so I apologize if this is too little or too much information.
graph1 <- ggplot(USA.2012to2021, aes(x = region, y = refugees, color = region, fill = region)) + geom_col()
graph1.animation = graph1 + transition_time(year)
file_renderer(dir = ".", prefix = "gganim_plot", overwrite = FALSE)
graph1.animation
I'm not using CSV data. Is that will be a problem?
Every time I run this it will be shown couldn't find function "prophet" or "make_future_dataframe"
This is the data i use
resp_jakarta <- GET("https://data.covid19.go.id/public/api/prov_detail_DKI_JAKARTA.json")
status_code(resp_jakarta)
cov_jakarta_raw <- content(resp_jakarta, as = "parsed", simplifyVector = TRUE)
cov_jakarta <- cov_jakarta_raw$list_perkembangan
new_cov_jakarta <-
cov_jakarta %>%
select(-contains("DIRAWAT_OR_ISOLASI")) %>%
select(-starts_with("AKUMULASI")) %>%
rename(
kasus_baru = KASUS,
meninggal = MENINGGAL,
sembuh = SEMBUH
) %>%
mutate(
tanggal = as.POSIXct(tanggal / 1000, origin = "1970-01-01"),
tanggal = as.Date(tanggal)
)
#Forecast
install.packages("prophet")
trying URL https://cran.rstudio.com/bin/macosx/contrib/4.0/prophet_0.6.1.tgz
Content type 'application/x-gzip' length 6317112 bytes (6.0 MB)
downloaded 6.0 MB
The downloaded binary packages are in
/var/folders/bl/q861y47s7b7cnym8hzmryv0c0000gn/T//RtmpTKLo8z/downloaded_packages
library(prophet)
This happens when i run library(prophet)
Loading required package: Rcpp
Loading required package: rlang
Error: package or namespace load failed for ‘prophet’ in dyn.load(file, DLLpath = DLLpath, ...):
unable to load shared object '/Library/Frameworks/R.framework/Versions/4.0/Resources/library/prophet/libs/prophet.so':
dlopen(/Library/Frameworks/R.framework/Versions/4.0/Resources/library/prophet/libs/prophet.so, 6): Library not loaded: #rpath/libtbb.dylib
Referenced from: /Library/Frameworks/R.framework/Versions/4.0/Resources/library/prophet/libs/prophet.so
Reason: image not found
date=as.Date(new_cov_jakarta$tanggal)
cases=new_cov_jakarta$kasus_baru
temp_prophet <- data.frame(date,cases)
temp_prophet <- temp_prophet %>% rename(ds = date, y = cases)
#Issues start from here
m <- prophet(temp_prophet)
And then this happens:
Error in prophet(temp_prophet) : could not find function "prophet"
future <- make_future_dataframe(m, periods = 30,freq="day")
Error in make_future_dataframe(m, periods = 30, freq = "day") : could not find function "make_future_dataframe"
tail(future)
forecast <- predict(m, future)
That's already been reported as an issue in prophet, and was suggested to install the package from source in order to fix it:
install.packages("prophet", type="source")
Also, double-check that both prophet.so and libtbb.dylib exist in your system.
#2개년(use: df_3 , MSE: 0.02313121)
#선형회귀모델
lm2 <- lm(data = df_3, formula = OPS_y1 ~ (OPS_y2+OPS_y3 + AVG_y2+AVG_y3 + G_y2+G_y3 + GW.RBI_y2+GW.RBI_y3 + H_y2+H_y3 + SAC_y2+SAC_y3)^2) %>% step(direction = "both")
Error in length(obj) : class name too long in 'length'
Once the code has been executed, it will be executed normally. However, if you change the data set and run it again, the same error occurs when you run the first code again. What's the problem? I went to the registry editing window and changed the value of 'LongPathsEnabled' to 1, but it was not resolved. Please solve the problem.
I had the sample problem when using stepwise regression with the step function. In my case there was some package conflict and all was fine after I specified stats::step(...) as follows:
lm2 <- lm(data = df_3, formula = OPS_y1 ~ (OPS_y2+OPS_y3 + AVG_y2+AVG_y3 + G_y2+G_y3 + GW.RBI_y2+GW.RBI_y3 + H_y2+H_y3 + SAC_y2+SAC_y3)^2) %>% stats::step(direction = "both")
As pointed out by user12282991, the problem may be due to package conflicts. The error most probably results from attaching the package recipes, which masks "step" from package:stats. Thus, stepAIC from package MASS or stats::step works.
library(recipes)
step(subclass = paste(rep("A",1000),collapse=""))
gives
Error in (function (x, ...) : class name too long in 'print'.
I have R 3.5.1 and RStudio 1.1.453 running on MacOS High Sierra 10.13.5, platform x86_64-apple-darwin17.6.0. I want to understand why I can print and export plots but can't use a graphics device to save the plots.
I can use R's extrafont package to embed the Corbel font into PDF graphs. I can save these graphs by using print() and then exporting via the Plot window. Using this method, the font embeds and displays perfectly.
However, I want R to save several dozen such graphs without having to manually print() and save each one. There are various methods for this.
One is R's PDF Graphics Device. Unfortunately, this device does not seem to interact nicely with spaces and other characters. Here's the function that produces the ggplot:
jobreport_grouped <- function(table, N)
{
#Group
table <- table %>%
group_by(Education, Desired) %>%
summarize(n())
#Order
table <- arrange(table, desc(`n()`))
#Response label
response_count <- sum(table$`n()`)
#Sample size label
samplesize <- paste("(N = ", sum(table$`n()`), ")", sep="")
#Grouped barplot
ggplot(table[which(table$`n()`>N),],
aes(fill=Education,
x=reorder(Desired,-`n()`),
y=`n()`)
) +
scale_fill_manual(values = paletteIDCN) +
IDCNtheme_grouped_dense +
xlab(paste("Number of Active Members: ",
member_count,
"\n",
"Number of Responses: ",
response_count,
sep="")
) +
ylab("Number of IDCN Members") +
ggtitle(paste(desired_title("Professional Areas"),
"\n",
today,
sep = ""
)
)+
geom_col(position="dodge")
}
And then a call of this function along with an attempt to write the plot
> getGroupedJobReport <- function(A,n){
+ p <- jobreport_grouped(A,n)
+ ggsave(p, filename = "~/TMP-R/TDP/plots/Desired_GROUPED.pdf", device = pdf,
+ width = 12, height = 7, units = "in")
+ }
> getGroupedJobReport(A1,2)
There were 50 or more warnings (use warnings() to see the first 50)
> warnings()
Warning messages:
1: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), ... :
font width unknown for character 0x20
2: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), ... :
font width unknown for character 0x27
3: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), ... :
font width unknown for character 0x20
After this, I tried a MacPorts installation of Cairo together with CRAN's Cairo package and got a different error:
> getGroupedJobReport <- function(A,n){
+ p <- jobreport_grouped(A,n)
+ ggsave(p, filename = "~/TMP-R/TDP/plots/Desired_GROUPED.pdf", device = cairo_pdf,
+ width = 12, height = 7, units = "in")
+ }
> getGroupedJobReport(A1,2)
Warning message:
In dev(file = filename, width = dim[1], height = dim[2], ...) :
failed to load cairo DLL
What alternatives to R's native PDF Graphics Device and Cairo are there? If any, which ones should I think of using?
Running the awesome gganimate package, but can't get the base example to work.
library(gapminder)
library(ggplot2)
library(gganimate)
theme_set(theme_bw())
p <- ggplot(gapminder, aes(gdpPercap, lifeExp, size = pop, color = continent, frame = year)) + geom_point() + scale_x_log10()
gg_animate(p)
Returns:
sh: C:\Program Files\ImageMagick-6.9.0-Q16\convert.exe: command not found
Error in cmd.fun(sprintf("%s --version", shQuote(ani.options("convert"))), : error in running command
sh: convert: command not found
Error in cmd.fun(sprintf("%s --version", convert), intern = TRUE) :
error in running command
I cannot find ImageMagick with convert = 'convert'
Error in file(file, "rb") : cannot open the connection
In addition: Warning messages:
1: In im.convert(img.files, output = movie.name, convert = convert, :
Please install ImageMagick first or put its bin path into the system PATH > variable
2: In normalizePath(movie.name) :
path[1]="file4421bbcfb7d.gif": No such file or directory
3: In file(file, "rb") :
cannot open file > '/var/folders/4y/5nw21h2j1dz9p960gfvl16ywlrpqh8/T//RtmpRywpkt/gganimate/file4421bb> cfb7d.gif': No such file or directory
I'm almost sure ImageMagick is installed. What is the missing link?