milihat.blogg.se

Two impossible shapes ontop of eachother
Two impossible shapes ontop of eachother












This means that absolutely positioned elements have no effect whatsoever on their parent element's size and your first will have a height of zero. However, the contents of an absolutely positioned element do not flow around any other boxes. An absolutely positioned box establishes a new containing block for normal flow children and absolutely (but not fixed) positioned descendants. It is removed from the normal flow entirely (it has no impact on later siblings). Your problem is that position: absolute removes elements from the normal flow: If the element has 'position: absolute', the containing block is established by the nearest ancestor with a 'position' of 'absolute', 'relative' or 'fixed'. container_row if you want the absolutely positioned elements to be positioned with respect to their parent rather than the document's body:

two impossible shapes ontop of eachother

You'll also want to have position: relative on. You will just have to use multiple layers of annotate() and specify each location ( see my original post in edit history for an example).First of all, you really should be including the position on absolutely positioned elements or you will come across odd and confusing behavior you probably want to add top: 0 left: 0 to the CSS for both of your absolutely positioned elements. Note that you can also use sal instead of sal2 if you want more control over where each text is mapped on the plot. Geom_segment(aes(x = 2, y = 0.015, xend = 5, yend = 0.015), col = "red") + # add a line between the stems and leaves (caveat: must choose custom coordinates for its location) Sal_x_position <- min(x) + (max(x) - min(x))/2 # the center of x-axis will be the center of the stem-and-leafĪnnotate("text", x = sal_x_position, y = 0, label = sal2, angle = 90, hjust = 0, col = "red") + Sal2 <- gsub("\\|" ," ", sal2) # change the vertical bar ("|") to a space if you want to later replace it with geom_segment() (optional depending on how you like your aesthetics) Sal2 <- paste(sal, collapse="\n\n") # here I am using two new lines to widen the line spacing # make sal into a single string, collapse using new lines ("\n") stem(x) # copy and paste this stem-and-leaf plot to a variable However, one alternative to get the two plot information onto the same plot is to use ggplot() with annotate() to show the stem() information of Plot 1 and geom_point() to show the scatter plot of Plot 2. Stem() does not actually produce a typical graphical plot (nor can I save or easily extract information from its structure), so I'm not sure how you can overlay the stem() output with a graphical plot, such as those produced by plot() or ggplot(). Another problem is that it will need tweaking to be more robust.įor example, replacing x with mtcars$drat would need changing the scale argument to 0.5.

two impossible shapes ontop of eachother

It appears to use floor(x+0.5) at lines 96 and 103, which explains the slight differences. at <- seq(min(x), max(x), length.out=length(bin)-1)Īxis(side=1, at=at, labels=trunc(bin), tck=-0.02, mgp=c(1,0.3,0), col="red", col.axis="red")Ī notable difference is that stem doesn't use round as I've done here.

two impossible shapes ontop of eachother

The actual characters to plot ( pch) come from the first digit after the decimal place. Then I use the rowid function from data.table to define the y-axis values, dividing by its length to get the densities so that the two plots are using the same y-axis system. xgr <- sort(cut(round(x,1), breaks = bin, right=FALSE, labels = FALSE, include = TRUE)) Then I use cut to assign the x values into the correct bins. h <- hist(round(x,1), right=FALSE, plot=F) I first use the hist function to define to "best" breakpoints, which I'm guessing is similar to what stem does. Now we need to reinvent the stem function from scratch. This is your density plot: par(mar=c(2,1,1,1))

two impossible shapes ontop of eachother

Stem(x) # you can see the result from the question. I certainly haven't incorporated any of stem's arguments (scale, width, atom). I've tried to replicate the stem function using simple R functions and this certainly doesn't match the C code, but it works for this sample dataset.

Two impossible shapes ontop of eachother code#

Plus, the code is written in C, which is available here. Unfortunately, the stem function doesn't return anything, which makes life difficult.












Two impossible shapes ontop of eachother