I am trying to create Violin Plots using the StatsPlots.jl library.
However, I would like to have the returned Violin plot to be horizontal instead of vertical as I want to show the distribution of a variable (e.g. Temperature) for different heights, eg. at 1000m, 2000m, 3000m ...
So it would be nice if the height was at the y-Axis while the temperature distribution was on the x-Axis.
Is there a way to swap the axes of a Plots.Plot struct, or is there an argument I could pass to violin() that does the trick?
Related
How can I do a density plot that is split across variables like the ones done in Figure 1 in this paper ? https://www.pnas.org/content/117/24/13386
Obivously, doing geom_density on filtered data then changes the value of the density towards the border, because it assumes zeroes right after 1.96 if coming from the left.
What I'd need is to compute the whole density, but only plot half of it
I am trying to combine a scatterplot with a bar plot. The bar plot should be on the right side of the scatterplot of each corresponding group specified in facet wrap. The two plots have the same unit on the y axis but the scaling of the bar might need to be adjusted so the barplot it's not too tall.
Here's an example.
data(mpg)
So far I have tried this, but I would the bar should be outside the scatterplot area. Additionally, in my data the x axis in the barplot is a factor with two levels, so it has a discrete scale and my scatterplot has a continuous x scale.
ggplot()+geom_bar(data=mpg,aes(x=10,y=displ,fill=trans),stat='identity',position='stack')
+geom_point(data=mpg,aes(x=displ,y=displ))+facet_wrap(~cyl)
Can I achieve to plot these two plot types side-by-side or do I have to use something like cowplot? I think that if I have to combine plots outside ggplot I will not be able to use factor_wrap, so I guess I have to do a for loop for each factor level and then combine everything?
I am trying to create a stacked area chart of 4 categories of data using geom_area in R. I am able to construct line charts for the categories using geom_line() but when I use geom_area to show shaded regions, the vertical scale is incorrect. It looks like it may be doing some summing of the data. My line chart code looks like this and produces an accurate plot with a range of values from 0 to approximately $800,000:
lp3b<-ggplot(
data=myHousing,aes(x=Year,y=Home.Value,color=State))+geom_line()
lp3b
My area plot code, below, produces a plot the visually is correct but the vertical scale goes from 0 - to about $1,600,000 which is definitely not the correct range of values. I checked the range of data values before and after plotting and the area chart definitely has the scale wrong.
lp3c<-ggplot()+geom_area(data=myHousing,
aes(x=Year,y=Home.Value,fill=State),alpha=0.5,position="stack")
lp3c
I am trying to plot data with a categorical x-axis variable and a continuous y-axis variable. The current plot is shown below:
A am trying to alter the height of the y-axis to make the plot taller and thinner. I know you can do this kind of thing with a continuous variable vs. continuous variable scatterplot using coord_fixed(), e.g.:
However, this works on the numeric ratios of the x and y data, which doesn't apply if one variable is categorical. Trying coord_fixed on my data with any input seems to just scale the plot exactly to the plot area:
Trying to adjust the canvas at the ggsave phase just adds white space around the plot, rather than changing the plot shape itself, which isn't what I'm looking for either:
ggsave(filename = paste(imgSaveDir,'RT_data_summ.png',sep=""),width=7,height=10)
Any help is appreciated!
I am creating a histogram with the following line:
hist(mydata$freq2,col="lightgreen")
This produces the image below:
I would like the bars to stay within the chart area. Why doesn't R increase the values of the X and Y axis, and how can I increase these values manually?
The bars to stay in the chart area. R calculates the axis dimensions based on your data and with default parameters even extends it a bit.
The axis with its labels is drawn for the boxplot only inside the label range.
If you draw a box around the figure, you will see that the plot uses up the space always the same disregarding of your data. So it is not the bars going outside the chart but the axis being restricted to the labels.
set.seed(12345)
par(mfrow=c(2,2))
plot_random_hist <- function() {
hist(rbeta(100,1,8)*runif(1))
# plot a box to illustrate the plot area
box(col="red")
}
replicate(4, plot_random_hist() )
Have a look at par("usr") to query the dimensions of your plot in user coordinates.
If you need to control the length of the axis and the ticks/labels you can use the axis command and suppress automatic axis in your hist call.
set.seed(12345)
hist(rbeta(100,1,8),yaxt="n")
at <- c(0,10,30,par("usr")[4])
axis(2,at=at,labels=round(at))