• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Plots of each DF column show the same Title (instead of the specific DF column name)

Resolved: Plots of each DF column show the same Title (instead of the specific DF column name)

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

Hi all!.
The R code below,
works great to display 4 plots,
one plot for each numeric column in the iris DF.
And that’s exactly the plots i need.
Problem is,
all 4 plots (one for each column),
have the same default Title at the top:
Histogram of x
…instead of a plot Title at the top, for each specific DF column name:
Histogram of Sepal.Length
Histogram of Sepal.Width,
etc.
Here’s the R code:

f <- function(x){ c( hist(x, freq = FALSE ), lines(density(x)) ) } sapply(iris[1:4], f) # where "f" is the FX f/above!. [/code]

What R-code am I missing?.
Help, please!…
SFer —
latest version of R, Rstudio, Ubuntu LINUX 20.04.

Answer:

par(mfrow = c(2,2))
f <- function(data, colname){ hist(data[,colname], freq = FALSE, main = paste("Histogram of", colname), xlab = colname) lines(density(data[,colname])) } sapply(names(iris)[1:4], function(x) f(iris, x)) [/code]

enter image description here

If you have better answer, please add a comment about this, thank you!

density-plot plot r sapply
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: How can I modify formData before sending it?

01/04/2023

Resolved: How to efficient create SimpleITK image?

01/04/2023

Resolved: How can I write CSS selector(s) that apply to table rows for all td elements on that row after a td with a certain class?

01/04/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.