tag:blogger.com,1999:blog-1275149608391671670.post8784066032129862262..comments2023-09-28T06:13:40.704-04:00Comments on SAS and R: Example 8.41: Scatterplot with marginal histogramsKen Kleinmanhttp://www.blogger.com/profile/09525118721291529157noreply@blogger.comBlogger10125tag:blogger.com,1999:blog-1275149608391671670.post-23088137178944857302018-12-17T11:29:47.528-05:002018-12-17T11:29:47.528-05:00This is a wonderful piece of code. All the layout ...This is a wonderful piece of code. All the layout work has been <br />done upfront and the user doesn't't have to worry about it.<br />It is clean and easily modifiable. And, as a bonus, it doesn't use ggplot :-) <br />Thank you for sharing it. Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-56137809552395439452016-12-22T14:41:30.689-05:002016-12-22T14:41:30.689-05:00The abline() function plots the OLS regression ont...The abline() function plots the OLS regression onto an existing plot. So you can just add <br /><br />abline(coef = coef(lm(y~x)))<br /><br />after the plot() function in the existing code.Ken Kleinmanhttps://www.blogger.com/profile/09525118721291529157noreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-71905596425240310652016-12-19T06:22:43.781-05:002016-12-19T06:22:43.781-05:00Hello community,
i am using the R code of Mr. Ken ...Hello community,<br />i am using the R code of Mr. Ken to generate the graph and it works.<br />I would like to ask now what do i need to add to this code in order to get a regression line.<br />My code is:<br />scatterhist = function(x, y, xlab="1", ylab="2"){<br /> zones=matrix(c(2,0,1,3), ncol=2, byrow=TRUE)<br /> layout(zones, widths=c(4/5,1/5), heights=c(1/5,4/5))<br /> xhist = hist(x, plot=FALSE)<br /> yhist = hist(y, plot=FALSE)<br /> top = max(c(xhist$counts, yhist$counts))<br /> par(mar=c(3,3,1,1))<br /> plot(x,y)<br /> par(mar=c(0,3,1,1))<br /> barplot(xhist$counts, axes=FALSE, ylim=c(0, top), space=0)<br /> par(mar=c(3,0,1,1))<br /> barplot(yhist$counts, axes=FALSE, xlim=c(0, top), space=0, horiz=TRUE)<br /> par(oma=c(3,3,0,0))<br /> mtext(xlab, side=1, line=1, outer=TRUE, adj=0, <br /> at=.8 * (mean(x) - min(x))/(max(x)-min(x)))<br /> mtext(ylab, side=2, line=1, outer=TRUE, adj=0, <br /> at=(.8 * (mean(y) - min(y))/(max(y) - min(y))))<br />}<br />ds = read.csv("popAhohenheim.csv", header = T, sep = ";",dec = ",", na.strings= "*", stringsAsFactors = F )<br />with(ds, scatterhist(AES, Flowering, xlab="AES", ylab="Flowering"))<br /><br /><br />Best wishesa ahttps://www.blogger.com/profile/03266750402365558610noreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-59888804436333864552015-12-14T10:19:22.953-05:002015-12-14T10:19:22.953-05:00ggplot makes this easier
####
library(ggplot2)
li...ggplot makes this easier<br /><br />####<br />library(ggplot2)<br />library(ggExtra)<br /><br />df <- data.frame(x, y)<br />p <- ggplot(df, aes(x, y)) + geom_point() + theme_classic() + <br /> stat_smooth(method="loess", formula = y ~ x, size = 2) <br />ggExtra::ggMarginal(p, type = "histogram")<br />Selcuk Akbashttps://www.blogger.com/profile/11545994169963407022noreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-8040106492022696772012-08-02T11:55:25.428-04:002012-08-02T11:55:25.428-04:00Hi JSF--
Anything is possible. This one turns ou...Hi JSF--<br /><br />Anything is possible. This one turns out to be "easy", within the somewhat opaque graphics template language. All you have to do is add a "regressionplot" within the layout cell that contains the scatterplot. My modified version has this text after the modification outlined above and adding the regression line:<br /><br />layout overlay / xaxisopts=(type=XTYPE) yaxisopts=(type=YTYPE); <br /> scatterplot y=YVAR x=XVAR / datatransparency=0 markerattrs=(symbol=circlefilled size=5px);<br /> regressionplot y=YVAR x=XVAR;<br /> endlayout;<br /><br />Hope that helps. To see more uses of the GTL, see this SUGI presentation paper: http://www2.sas.com/proceedings/sugi31/262-31.pdfKen Kleinmanhttps://www.blogger.com/profile/09525118721291529157noreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-80069708847002099192012-08-02T10:57:05.724-04:002012-08-02T10:57:05.724-04:00Can a regression line be added to the scatterplot ...Can a regression line be added to the scatterplot in SAS?JSFhttps://www.blogger.com/profile/12929588374754553230noreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-22869803098347892232012-08-02T10:55:21.825-04:002012-08-02T10:55:21.825-04:00This comment has been removed by the author.JSFhttps://www.blogger.com/profile/12929588374754553230noreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-62839820582741959772011-06-21T22:45:20.720-04:002011-06-21T22:45:20.720-04:00Hi, Rick-- I had intended to link to your entry, b...Hi, Rick-- I had intended to link to your entry, but that got lost in a draft somewhere. Thanks for correcting that omission.<br /><br />And thanks for that idea, mkao-- makes sense to me. As a challenge, can you suggest how to modify the R code to make a title print correctly? I was unable to do it in the time I had available before this entry had to run.Ken Kleinmanhttps://www.blogger.com/profile/09525118721291529157noreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-25990078719302823042011-06-20T17:44:52.328-04:002011-06-20T17:44:52.328-04:00I think changing the order of plot order in R coul...I think changing the order of plot order in R could be helpful. so if we let the scatter plot to be plotted last then after we have drawn the graph, we can super-impose loess or regression lines afterward.Anonymoushttps://www.blogger.com/profile/17074814198177240918noreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-52715717812452866392011-06-20T15:42:56.369-04:002011-06-20T15:42:56.369-04:00For more details on modifying the SGRENDER code (i...For more details on modifying the SGRENDER code (including how to omit large sections of it), see http://blogs.sas.com/iml/index.php?/archives/139-How-to-Create-a-Scatter-Plot-with-Marginal-Histograms-in-SAS.htmlRick Wicklinhttps://www.blogger.com/profile/13919716786757842151noreply@blogger.com