How to set range of y axis on stacked barplot crossing the x-axis? - r

I have a question how to modify stacked barplot crossing the x axis presented here Stacked barplot crossing the x-axis. I want to set yaxis range from eg.-10 to 10. But when I've used ylim(-10,10) negative values appear on the left and scale_y_continuous(labels=abs) doesn't work (like in: http://i.stack.imgur.com/JwgW9.png). How to set range on yaxis and have positive values on both sides from zero?

Related

plot two lines on the same axes without leading to overlapping values on the y axis

Is there a way to change the y axis in R so that there isn't overlapping numbers when you plot two trend lines ?
I have managed to plot the two lines I am considering in one graph but there is a nasty Y axis - does anyone know how to avoid this happening?

How to reduce space between axis ticks and axis labels in R

I have the below plot generated in R:
Code:
ecdf.bdel<-ecdf(bDE[,6]) #### cumulative distribution of a vector of numeric values
curve(1-ecdf.bdel(x),col="red",xlim=r,xlab="r2",ylab="Fraction of SVs tagged") ###plotting inverse ecdf curve
the plot is as expected. However, it leaves huge white space between axis ticks and axis labels and also between axis labels and axis labs.
Could someone offer any tip to reduce the white space.
Insert mgp parameter like this, and see if it works. Also see mar parameter for margin from all the sides. You can use both together inside par() function to solve your problem.
par(mgp=c(3,1,0),mar(5,4,4,2)+0.1)
curve(1-ecdf.bdel(x),col="red",xlab="r2",ylab="Fraction of SVs tagged")
The first value in mgp is where your axis labels moves either close to or far from axis, less value means closer to axis and high value means far from axis on both the axis i.e. x and y axis.
The second value in mgp is where your tick labels moves either close to or far from ticks, less value means closer to tick and high value means far from ticks on both the axis i.e. x and y axis.
The third value in mgp is where your ticks moves either close to or far from axis line itself, less value means closer to axis line and high value means far from axis line on both the axis, i.e. x and y.
mar is a numerical vector of the form c(bottom, left, top, right) which gives the number of lines of margin to be specified on the four sides of the plot. The default is c(5, 4, 4, 2) + 0.1.
Remove xlim from curve() function. Your graph condition
par(mgp=c(10,4,0),mar=c(11,11,5,5)+0.1)
curve(1-ecdf.bdel(x),col="red",xlab="r2",ylab="Fraction of SVs tagged")
par(mgp=c(3,1,0),mar=c(5,4,4,2)+0.1)
curve(1-ecdf.bdel(x),col="red",xlab="r2",ylab="Fraction of SVs tagged")
Example: Using plot instead of curve. It is similar
First Case:
par(mgp=c(7,3,0),mar=c(8,8,5,5)+0.1)
plot(1:10,xlab="X Axis", ylab="Y Axis", main="My Plot")
Second Case
par(mgp=c(3,1,0),mar=c(5,4,4,2)+0.1)
plot(1:10,xlab="X Axis", ylab="Y Axis", main="My Plot")
Is this what you want? I had no other option to show the plot I will add the code if this is what you want.
This is what I did:
data<-read.table("Ld.txt",F)
ecdf.bdel<-ecdf(data$V1) #### cumulative distribution of a vector of numeric values
curve(1-ecdf.bdel(x),col="red",xlab="r2",ylab="Fraction of SVs tagged") ###plotting inverse ecdf curve

How to make line graph from x-axis values versus y-axis values in xcode?

How to create x-y graph with x-axis values for example x1,x2,x3 versus y-axis values for y1,y2,y3?

Changing X-axis position in R barplot

I have two values of averages LR50<-(424.8, 425.7). I want to plot these as a barplot barplot(LR50). Now, I don't need any of the information except from ylim=c(424,426.5). When I change the x-axis axis(1,at=c(0,10), pos=424) there is still bar plot that falls below the axis.
How do I get the barplot to only plot from the new x-axis at y=424 and up?
You will need to use the xpd parameter (and set it to FALSE), this will clip the plot to the plotting region.
barplot(LR50,ylim = c(424,426.5),xpd=FALSE)
axis(1,at=c(0,10),pos=424)

How to create side-by-side bar charts (for multiple series) with ggplot?

I have two sets of data (3 columns: x=categorical, y = numerical, l = location) and I would like to create a bar chart with the categories on the x axis and, for each value of the category, two vertical bars, coloured differently, with the y values for each location. By the default, Excel/OpenOffice produce this kind of chart.
I tried
qplot (x,y,data=mydata,col=location, geom="histogram")
but it produces stacked bars, not side by side. I then looked in the ggplot2 documentation and didn't find any other geom I could use (see below for full list).
Is this not possible with ggplot2?
Thanks in advance.
Name Description
abline - Line, specified by slope and intercept
area - Area plots
bar - Bars, rectangles with bases on y-axis
blank - Blank, draws nothing
boxplot - Box-and-whisker plot
contour - Display contours of a 3d surface in 2d
crossbar - Hollow bar with middle indicated by horizontal line
density - Display a smooth density estimate
density_2d - Contours from a 2d density estimate
errorbar - Error bars
histogram - Histogram
hline - Line, horizontal
interval - Base for all interval (range) geoms
jitter - Points, jittered to reduce overplotting
line - Connect observations, in order of x value
linerange - An interval represented by a vertical line
path - Connect observations, in original order
point - Points, as for a scatterplot
pointrange - An interval represented by a vertical line, with a point
in the middle
polygon - Polygon, a filled path
quantile - Add quantile lines from a quantile regression
ribbon - Ribbons, y range with continuous x values
rug - Marginal rug plots
segment - Single line segments
smooth - Add a smoothed condition mean
step - Connect observations by stairs
text - Textual annotations
tile - Tile plot as densely as possible, assuming that every tile is the same size
vline - Line, vertical
There is a position argument that defaults to stack here. Use:
qplot (x,y,data=mydata,col=location, geom="bar", position="dodge")
It is in the manual, just search for "dodge". Also, you probably want a "bar" geom if the y values give the height of the bar.

Resources