Can someone tell me if there is a way to align plotly plots in R-Markdown?. More specifically: Currently my plots are being placed one after another. I would like to have a grid-like format. I achieved this before, using the simple plot function, but that doesn't seem to work with plotly.
The following is an example of my prior code, that worked with the simple plot function. Can I make that work, assuming I were using plotly?
Thanks in advance.
{r comment = NA,fig.width=14, fig.height=14}
layout(matrix(c(1,2,3,4,5,6,7,8), 4, 2, byrow = TRUE))
m_alt <- miete[miete$baujahr <= 22,]
m_neu <- miete[miete$baujahr > 22,]
plot(table(m_alt$bezirk),main="",ylab="Frequency",xlab="Bezirk")
plot(table(m_neu$bezirk),main="",ylab="Frequency",xlab="Bezirk")
plot(table(m_alt$wohnflaeche),main="",ylab="Frequency",xlab="Wohnfläche")
plot(table(m_neu$wohnflaeche),main="",ylab="Frequency",xlab="Wohnfläche")
plot(table(m_alt$wohnlage,m_alt$zimmerzahl),main="Altbau: Wohnlage u. Zimmerzahl")
plot(table(m_neu$wohnlage,m_neu$zimmerzahl),main="Neubau: Wohnlage u. Zimmerzahl")
plot(table(miete$bezirk,miete$zimmerzahl),main="Bezirk u. Zimmerzahl")
plot(table(miete$warmwasser,miete$bezirk),main="Warmwasser u. Bezirk")
Related
I am trying to insert of a simple Venn diagram in an jupyter notebook on R. I have been able to generate a simple 2-set diagram using the VennDiagram library. However I can't seem to figure out how to work the triple diagram in way that yields 2 intersecting sets that are in a subset of another larger set.
Maybe I'm using the wrong library?
Edit:
This is for an illustration, I just need to draw an example of a Venn Diagram. The data would be something like:
S=(1,2,3)
A=(1,2)
B=(2,3)
The latest development version of my r package eulerr is now able to take a list of sample spaces as input. It, however, produces euler diagrams (proportional Venn diagrams) (which is why your specifications won't result in two diagrams intersecting within another).
# devtoools::install_github("jolars/eulerr")
library(eulerr)
ll <- list(S = c(1, 2, 3), A = c(1, 2), B = c(2, 3))
fit <- euler(ll)
plot(fit)
If you want two intersecting circles within a third, try the following:
plot(euler(c(S = 5, "A&B&S" = 3, "A&S" = 1, "B&S" = 1)))
t = table(iris$Species)
pie(t, labels=rownames(t))
This draws a simple pie. I want that the labels are a little bit more away from the pie. I checked the par() docu but I think I don't understand it completly and I missed the option for that.
This question is explicite about R's own pie() and not related to any other extern R package.
I don't think you can really do this with the pie function. If you look at View(pie) you'll see that the labels are drawn using the text function. This means that they are not really axis labels, and that par has little effect on them. You could try to do stuff by using the arguments of the text function (i.e. pos = 2, offset = 1) but this will affect all labels in the exact same way and results in warnings. To me it seems that the only way is the stupid way by adding some spaces before/ after labels. ie:
t = table(iris$Species)
nms = rownames(t)
# spaces needed after the labels
nms[2] = paste0(nms[2], strrep(' ', 7))
# spaces needed before the labels
nms[c(1, 3)] = paste0(strrep(' ', 7), nms[c(1, 3)])
pie(t, labels = nms)
If you want to a better solution, you could rewrite the pie function to be a bit more flexible or use a different package.
I'm having some trouble visualizing some data in an R Markdown document. I'm attaching a picture for your reference.
I would like the graphs produced to be larger, and would expect the HTML page to allow for these graphs to be spread out, but they are all coming back "squished"
g <- ggplot(item_loc_metrics, aes(capc_ssp_ratio, avg_wk_bkrm_eoh)) + geom_point(color="firebrick")
g
I run this and it returns a nicely formatted graph:
This snippet of code works fine, but I would like to cut this same graph 60+ times based on the store I'm looking at. I've tried to to do that with this bit:
g2 <- ggplot(item_loc_metrics, aes(capc_ssp_ratio, avg_wk_bkrm_eoh)) + geom_point(color="firebrick") + facet_wrap(~CO_LOC_N, ncol=5, scales = "fixed", shrink = FALSE)
g2
I end up then getting something that looks like this:
To let this question have an answer, I add my two cents.
You can increase fig.height and fig.width(as suggested in the comment) and set ncol to one.
#qcc package(spc charts)
library(qcc)
A <- c(10,20,30)
B <- c(25,35,44)
par(mfrow = c(2, 1))
qcc(A,type="xbar.one")
qcc(B,type="xbar.one")
problem is : chart(B) is replacing chart(A) instead of positiong in the second row.
someone please let me know how to overcome these problem
There probably is a kind of bug and also, you need to use plot.
Here is a solution to make it work :
qA<-qcc(A,type="xbar.one")
qB<-qcc(B,type="xbar.one")
par(mfrow=c(2,1))
plot(qA, restore.par=FALSE)
plot(qB)
The strange (probably bug?) part is that doing the below thing doesn't work... :
par(mfrow=c(2,1))
plot(qcc(A,type="xbar.one"),restore.par=FALSE)
plot(qcc(B,type="xbar.one"))
I'm having trouble adding some text to an plot of time series data in R using xts. I've produced a simple example of the problem.
My text() command seems to do nothing, whereas I can add a points to the plot. I've tried to keep the code simple by using defaults where possible
require(quantmod)
# fetch the data and plot it using default options
getSymbols('MKS.L')
plot(MKS.L$MKS.L.Close)
# try to add text - doesn't appear
text(as.Date('2012-01-01'),y=500,"wobble", cex=4)
# add a point - this does appear
testPos <- xts(600, as.Date('2012-01-01'))
points( testPos, pch = 3, cex = 4, col = "red" )
Any help appreciated - I'm pretty new to R and I've spent hours on this!
Not a direct answer, but the plot.xts function that comes with the xts package is not fully developed.
You're much better off using plot.zoo or plot.xts from the xtsExtra package (which was written as a Google Summer of Code project with the intention being to roll it into the xts package)
Either of these will work:
plot(as.zoo(MKS.L$MKS.L.Close))
text(as.Date('2012-01-01'),y=500,"wobble", cex=4)
#install.packages("xtsExtra", repos="http://r-forge.r-project.org")
xtsExtra::plot.xts(MKS.L$MKS.L.Close)
text(as.Date('2012-01-01'),y=500,"wobble", cex=4)