adding density on axes in ggplot2 [closed] - r

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I was doing some pretty plots with these density bars on the axes,
but since there I've lost the code and the ability to reproduce the bars.
It would be wonderful if someone could point me to the right command
Thanks

I believe you're looking for geom_rug; here is an example:
ggplot(mtcars, aes(wt, mpg, colour = as.factor(am))) + geom_point() + geom_rug()

Related

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.

Removing the frame line from the geom_violin() function in R [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
Does anyone know how I can remove the curved frame line and only leave the dots in the violin plot when using geom_violin function? As shown in the graph below
first I think that doesn't make sense you remove the shape because it is really helpfull to visualize the distribution of the variable.
But, if you really want it, you have to use geom_dotplot() insted of geom_violin().
Your code could be like this:
ggplot(mtcars, aes(factor(vs), drat)) +
geom_dotplot(binaxis ="y", stackdir = "center")
Then, your result is gonna be:

How can tune the plot colors, labels, etc. to make it beautiful? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
What's the meaning of beautiful chart for humans and which theme or color gradients should use, so everybody could say, visually beautiful color and harmony used for the specific chart. Especially, I want to tune colors, labels, etc. in R histogram to gain full mark in my homework. Any help would be appreciated.
You can use this code to have a beautiful histogram
col <- c("#B2182B", "#D6604D", "#F4A582" ,"#FDDBC7", "#D1E5F0", "#92C5DE", "#4393C3" ,"#2166AC")
hist(precip,breaks = 13,col=cm.colors(5),freq =F,xlab = "xlab",ylab = "ylab",main = "main")
your output be something like this :
or this one to have more colorful plot
hist(precip,breaks = 13,col=rainbow(13),freq =F,xlab = "xlab",ylab = "ylab",main = "main")
your output be something like this :
for more details about the attribute of hist function you can look at this link:
https://www.rdocumentation.org/packages/graphics/versions/3.5.3/topics/hist

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.

Resources