Histogram with Frequency and Density axises simultaneously in R -


I can add both density and frequency plots like this

  hist (ex, Col = "red", prob = TRUE) lines (density (ex), col = "red")  

But is it even possible that both the letters on each side can also happen? Just an example:

fake plot

Updated: Solution genuine Depending on the data:

  # margin from the correct equals (Mar = C (5, 4, 4, 4) + 0.1) Hist (east, col = "red", prob = true ) Line (density (ex), col = "red") # axis axis ticks (4, at = seq (0,0.4,0.1) * 50, label = seq (0,0.4,0.1) * 2500) # axis Label Mtext ("Frequency", Side = 4, Line = 3)  

Your comment Two: Depending on your code, use Base R - here There is a quick walk on a formula - where you do not have to manually define the axes. The obvious difficulty is either density or the frequency will not be pretty / round number (if you want them to be rounded then the ticks can be used in different places will be on). I think it is more sensible for the density at defined intervals. This requires constant continuous punctuation.

For the plot I provide the density of LHS axis, but it will be easy to simplify.

  histfreq & lt; - function (X, lines = true, ...) {par (CR = 5 (5, 4, 4, 4) 0.1) H & lt; - Hist (X, plot = FALSE) n.obs & lt; - Length (na.omit (x)) D & LT - Density (NOIT (x)) H < - Hist (X, Probe = True, Yax = "N", Yelim = C (0, Max (H $ density, D $ y)) * 1.1), ...) # axis ticks and label # Y axis (2 # 4 (Y, 0, H $ density), label = format C (beautiful (C (0, H $ density)), points = 1, format = "F" = Beautiful (C (0, H $ density)), label = format C (Significant (C (0, H $ density)) * N.obs * Exclusive (difference (H $ breaks)), points = 2 ), Numeric = 0, format = "F")) Amtext ("Frequency", Side = 4, Line = 3) If (L In) lines (D, ...)} # Call plot Histfrek (rnorm (57), col = "red")  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

lua - HowTo create a fuel bar -