Inverting a single axis plot in R - r

I plotted a single column in R with the code below
plot(datanew$cap)
But what I actually need is that the points on the x-axis should be on the y-axis while the point on the y-axis should be the x-axis. If anyone has an idea on how I can do this, I will greatly apreciate.

Plotting via
plot(datanew$cap)
is basically the same as
plot(seq(length(datanew$cap)), datanew$cap)
You can use this to your advantage by swapping the arguments (or specifiying x- and y-coordinates explicitly):
plot(x=datanew$cap, y=seq(length(datanew$cap)))

Related

Only show every nth axis tick marks in ggplot

I am able to group the dots by assigning my categorical data specific x- and y-values with empty spaces in between. Instead of showing every single tick mark on the axes,
or showing no ticks at all,
I would like to show only every nth tick mark on the axes corresponding to the labels. Can this be done in ggplot? Or maybe there is a different approach to generate the plot I am looking for.
Hard to answer without a reproducible example. You could try adding a scale_x_continuous() and scale_y_continuous() statement.
ggplot(data,aes(x,y))+
scale_x_continuous(breaks=c(0,2,4,6,8,10),labels=c("0","2","4","6","8","10"))

(Over)plotting points on a line plot

I am trying to plot individual data points on a line plot I already made as follows:
p=plot('3.29*exp(-17.4*(x^2))-0.908',xrange=[0.,1.],yrange=[-1.,1.5])
I first tried overplotting a point like this but nothing appears on the graph
estimate1=plot([0.549],[0.755],overplot=1)
When I give the plot function two points to overplot by adding another set of x and y values in input vectors, it connects them.
estimate=plot([0.349,0.9595],[0.555,0.9995],overplot=1)
How can I (over)plot the points without them being connected?
You should be able to set linestyle = 6 which will plot without the line.
I found a way around the problem I was having. After choosing a symbol for the points I wanted to show, I simply set the transparency of the line connecting them to 100 and the symbol transparency to 0.
estimate1.symbol='diamond'
estimate1.transparency=100
estimate1.sym_transparency=0
The work around is not elegant, but it works.

Double opposite histogram in ggplot

I would like to know how to do this kind of graphs using ggplot :
https://image.noelshack.com/fichiers/2019/21/3/1558514850-plot-example2.png
This is an excel graph. I already know how to do each of the two histogram (left and right) but I don't know how to plot the two of them on the same graph, separated on the middle of the graph, with this duality.
Maybe using a specific package or geom I don't know yet ?
Thanks for help
You need to build your histogram with geom_col(), to have positive values for one groupe, négative values for the second groupe, and then use coord_split()

R Plotly - Mirroring y axes

is it possible to "mirror" the y axis with R plotly ? I would like to do something similar to this, but with a mirrored y-axis, in order to plot 2 by 2 some data, one replicate one the regular yaxis, and the other on the mirrored axis (that would prevent me to convert a half of my data to negative values).
Also, if possible, I want the bars to be on the same place (one right under the other), not on two distinct sides like showed in the link.
Thanks in advance.

How can one create a double horizontal axis for a plot in ggplot2?

I need to show the values on the horizontal axis (aka abscissa, aka x-axis) converted into other units. Hence the need for a second axis.
It is not currently possible. Hopefully after this summer.

Resources