DudeWah
DudeWah

Reputation: 361

R - Changing Values and Scales for Axes

Using an inverse transform method to simulate a pareto distribution. I made the density histogram of the sample with the Pareto(2, 2) density superimposed for comparison. The graph doesn't look like what I wanted it to though.

I'd like for my y-axis to go from (0.00,0.08) with a scale of .02

I'd like for my x-axis to go from (0,120) with a scale of 20.

I tried using a few commands such as xticks, yticks, but couldn't get the result I wanted. Any suggestions?

x <- runif(100, min = 0, max = 1)

a <- 2
b <- 2

gen_pareto <- b/(1-x)^(1/a)


plot(x, gen_pareto)

hist(gen_pareto, prob = TRUE)

lines(density(gen_pareto), # density plot
      lwd = 3, # thickness of line
      col = "blue")

enter image description here

Upvotes: 1

Views: 201

Answers (1)

PKumar
PKumar

Reputation: 11128

Here is one approach to your solution :

par(mfrow=c(1,2))
hist(gen_pareto, prob=T,xlim = c(0,120), ylim = c(0,.8))
lines(density(gen_pareto), 
      lwd = 3, 
      col = "red")

However, I feel the below solution is much better but it doesn't qualify the boundary conditions you have said.

hist(gen_pareto, prob=T,xlim = c(0, max(density(gen_pareto)$x)), ylim = c(0, max(density(gen_pareto)$y)))
lines(density(gen_pareto), 
      lwd = 3, 
      col = "red")

enter image description here

Upvotes: 1

Related Questions