Controlling inner figure margins in R - r

I must have changed something in my par() settings, but I cannot recall what. It looks like my inner figure margins must have changed somewhere. This is obvious whenever I add lines, using the lines(), abline(), or points() functions during plotting.
Below is an image to illustrate the problem:
The black solid line at y=0 represents an abline(h=0). As you can see, the line just crosses the plotting region.
Any ideas on how to fix this? I have tried multiple things, but did not come to a solution for this problem just yet.

The answer to my problem was given by setting par(xpd=FALSE) .
Thanks to Ben Bolker.

Related

Plot Order of plots and all drawn elements like line.new or label.new

It was my understanding that the plot order was the same as the occurrence in the code. So if I plotted a line on code line 23 it would be plotted before (and appear behind) a label that was defined from code line 98.
In a workaround to my last question, I am using a line set to 30 px and a transparency of 75 to create a fill. The problem is it is plotting over the top of labels that are defined much later in the code and because of their location should be plotting on top of the line, but they are not.
I have searched everywhere, pine manual vs 4, Kodafy, and here on Stack to find exactly what the output order of drawing, labels, line, and plots are.
If anyone knows the solution to my specific problem or where I can find the information resources to resolve it myself I would be very grateful.
Last Post referred to above: https://stackoverflow.com/questions/69236171/i-want-to-fill-between-two-extended-line-new-pine-script-is-not-having-it-√/69241461#69241461
Thanks, Michael
try adding this to you study() line:
explicit_plot_zorder = true
from the refman:
"explicit_plot_zorder (const bool) Specifies the order in which the indicator's plots, fills, and hlines are rendered. If true, the plots will be drawn based on the order in which they appear in the indicator's code, each newer plot being drawn above the previous ones. This only applies to plot*() functions, fill, and hline. Optional. The default is false."
Hope that can fix your problem
Cheers, and best of luck with your trading and coding

ggplot to add space in between group

I am working on this hazard ratio chart, using ggplot function and hope you guys could help. I am trying to add the space in between the group “Income” and “Region” . There is function called position_dodge, but I still not quite get it yet. See the image below for the layout. I'm trying to get something liekt that. Thanks in advance for help~! here is my current code, and the position_dodge not helping with adding space right now

R plot margins way too large when plotting networks in igraph

I've searched SO and haven't found a solution that I can get to work. I don't have any replicable data, but I've got the graph below illustrating my issue: my plot is too small. Any ideas on what my issue might be? The picture below has about half of its area as white space.
Set the margin parameter using:
par(mar=c(0,0,0,0)+.1)
See more info on par here: http://rfunction.com/archives/1302
Just in case that someone has a similar problem, you can change the margins by adding margins in plot:
plot(g, layout = layout_nicely(g),... margin=0)
See more details here: https://igraph.org/r/doc/plot.common.html

Put Y-Axis along x=0 line in Bokeh figure

I would like to have my y-axis go right up through the x=0 line in my figure, rather than have it on the left side. Is there an easy way to achieve this with Bokeh?
Currently not available in Bokeh, as of 0.12.1. There is an open issue for this feature.
Have seen someone visually faking it using spans when replicating this infographic - but note labels still off to the left.
Here's the mailing list discussion: https://groups.google.com/a/continuum.io/forum/#!topicsearchin/bokeh/fivethirtyeight/bokeh/_dKphJePDwg
I was attempting to do this and it looks like there is now a solution to this. You can set the figure.yaxis.fixed_location attribute to zero.
As an explicit example using bokeh 1.0.4:
# ... bokeh imports
p = figure(plot_width=300, plot_height=300)
p.patch([-1,0,1], [-1,1,0.5], alpha=0.5)
p.yaxis.fixed_location = 0
show(p)
returns the figure:
You can also do this for the x-axis or both.

R plot axes don't meet and data extends beyond them

I have a VERY basic plot in R, and I'd like to solve two issues. Here is the code which produces the plot:
plot(o,n,bty="n",pch=21,cex=1.5,bg="gray",xlab="y",ylab="x",lwd=2)
And, here's the plot
There are two unwanted behaviors of this plot that I'm trying to fix. And I don't know how to do either one (nor do I understand why R doesn't do these things already...)
The X and Y axes do not meet. There is a gap near the origin in this plot. I want to remove that. The axes should touch, just like any other graph.
The data extends past the axis is both the X and Y direction. This clearly is unwanted. How can I fix this without having to manually make my own axis. Seems like there should be something more intuitive here.
bty="l".
You may also want to use something like:
xlim=c(0.02, 0.24), ylim=c(0.02, 0.24)
if you don't like the default limits of your two axes.
In general, check out ?par for guidance on both of these and many other options.
Try leaving out bty="n" or replacing it by bty="L" if you really do not want a box with edges above or on the right

Resources