How to include image in a animated chart bar with R? [closed] - r

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
How to include images in the bars, in an animated chart bar with R?
The animated chart is based on this code:
https://github.com/amrrs/animated_bar_charts_in_R
I would like to add flags to each bar, as in:
https://www.technologyreview.com/2020/03/27/950263/the-covid-19-pandemic-in-two-animated-charts/
But my flags are personalized, so the package "GGIMAGE" doesn't work. I want to upload my own images.

Hope I didn't ignore some concern of yours, but if it is only that you have your own image files and don't want to use ggimage::geom_flag, then ggimage might still be useful to you - you just have to provide the path to your own image as a parameter to ggimage::geom_image.
It should be easy if you name the flag images simply the same as your country_name+ .png .
Unfortunately I know little about that animation code and the example you shared, so you might need to tamper a little to get the positioning right :)
library(ggimage)
anim <- ggplot(gdp_formatted, [...]) +
[...] +
ggimage::geom_image(
aes(
# x = rank,
y = value,
image = file.path(<path_to_local_folder>, paste0(country_name,'.png')),
# size = ...
)
)
Fair warning, the size aesthetics param was really annoying to me and only by pure luck I got it under control (in my use case, images had different dimensions and needed to be rescaled).
I'd suggest to preprocess them so they fit and just not bother with this part :)

Related

scale_fill_manual() not respected [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 days ago.
Improve this question
I'm trying to create a geom_rect plot with rectangle coloring depending on a cell value. So far is working but when I try to change the default coloring the the ones I want nothing happens.
Color should depends on a value that can be a number from 1 to 3.
Here is the code that I have so far:
colors=c("2"="gray","1"="green","3"="blue")
plot = ggplot()+ geom_rect(data=test[[1]],mapping=aes(xmin=test[[1]][,2]-0.40,xmax=test[[1]][,2]+0.40,ymin=test[[1]][,3],ymax=test[[1]][,4]),fill=(test[[1]]$`Significant Results`+2))
plot + scale_fill_manual(values=colors)
This gives the plot like I want but with different fill colors. It seems that scale_fill_manual() is not respected.
When I run the code I get this message:
"Scale for fill is already present.
Adding another scale for fill, which will replace the existing scale."
Which is expected but the colors do not change at all.
I have tried using different colors but still I have the same problem.

Coloring in ggplot [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I need to fix the color scaling for a ggplot image I made. This is the image from ggplot...
With the following r code...
toLonger(dge_cpmlogtwo) %>%
ggplot(aes(x = Expression, color = sample_id)) +
geom_density() +
theme(axis.text.x = element_text(angle = 90, hjust = 1))
toLonger is an inhouse function. I can't post the data here because its just too large and I don't think it's relevant for the question. Mainly I jsut need to know
It's a surprisingly difficult challenge to identify 25 clearly distinguishable colors. This answer in the graphic design part of stackexchange gives a good overview of some attempts to do so.
A few other places to look:
How to generate a number of most distinctive colors in R?
R color palettes for many data classes
https://stackoverflow.com/a/6076605/6851825

R plot function: Increase size of legend scale tick labels [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I am using plot() for some raster images. I want to increase the size of the legend scale tick labels. Any ideas?
Following the documentation for raster::plot(), any extra parameters passed to it are passed to fields::image.plot(). See: image.plot
Based on the answer to this: Increase font size in legend of image.plot, you should be able to pass
axis.args = list(cex.axis = font_size)
as a parameter to your call to plot() to change the legend tick label size.

How to position the plot legend outside the plot in the bottom-right [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I'm using the latest ggplot2 and currently do p + theme(legend.position='right'). The function theme is well documented and combining bottom and right doesn't seem possible. However, maybe there is an alternate way to achieve this?
You can use 2-element numeric vector for the position, something like:
p+theme(legend.position=c(0.85,0)
The problem is, it will overlap the plotting area.
And if you want to force it to be in one horizontal line, you can add:
p+guides(fill = guide_legend(nrow = 1))
EDIT
I used plot.margin to expand the area at the bottom, you can play with the parameters:
p+
guides(fill = guide_legend(nrow = 1))+
theme(plot.margin=unit(c(1,1,4,0.5),"cm"))+
theme(legend.position=c(0.85,-0.7))
OR
p+
theme(plot.margin=unit(c(1,1,4,0.5),"cm")) +
theme(legend.position=c(0.85,-0.7))
NOTE
Using Rstudio, when I export the image at certain width*height I don't get the legends, but if I drag and adjust the view before exporting as follows, it works.

rCharts - Manipulating Background Color and Suppressing Axes

These are probably separate questions but they both relate to controlling the look of an rCharts/Polycharts plots (to that end, my meta-question is: Where can I find a complete source for all the fields/methods for rCharts/Polycharts?)
My specific questions are:
1) How do I change the background color of the plot? Specifically, I need a color background instead of the default white.
2) How do I suppress the axes (and associated labels and ticks)?
Most of the SO posts with workarounds for the above are for nvd3.
The documentation found here:
https://media.readthedocs.org/pdf/rcharts/latest/rcharts.pdf
Was mostly just some basic examples, but nothing covering the above. I did find this thread on github from 2 years ago, noting that complete documentation was on the to-do list.
https://github.com/ramnathv/rCharts/issues/221
So maybe I'm just not finding it?
Thanks

Resources