I'm plotting a cdf of some data, and I've added logarithmic scale on the "x" axis. The ticks spacing is exactly as I want it to be, but I'd like to be able to add some tick marks on specific points.
I don't want to change the distribution of the ticks in my plot, from n by n
to m by m
, I want simply to have, among the ticks from n by n
, some further tick marks on some values.
I'd like to have it reflected in both x
and y
axis, so that I can fit a grid into these new marks throughout the graph.
So far I have the graph, and the grid -- I don't mind about having the grid behind or upon the graph, I just want to add some custom ticks.
# Cumulative Distribuition
pdf("g1_3.pdf")
plot(x = f$V2, y = cumsum(f$V1), log = "x", pch = 3,
xlab = "Frequency", ylab = "P(X <= x)",
panel.first = grid(equilogs = FALSE))
axis(1, at = c(40, 150))
abline(h = 0.6, v = 40, col = "lightgray", lty = 3)
abline(h = 0.6, v = 150, col = "lightgray", lty = 3)
dev.off()
UPDATE: The graph I have so far:
To create a plot with tick marks manually between X-axis values in base R, we first need to create the plot without X-axis labels then add the axis values using axis function with appropriate labels, this will create tick marks as well as labels.
Adding minor ticks to graphs is very simple. There are two mains ways, using the continuous scale functions such as scale_x_continuous() or using the guides() function, both from ggplot2 . Note that guide_prism_minor() does not work with discrete axes as they do not have minor breaks.
To set labels for X and Y axes in R plot, call plot() function and along with the data to be plot, pass required string values for the X and Y axes labels to the “xlab” and “ylab” parameters respectively. By default X-axis label is set to “x”, and Y-axis label is set to “y”.
Create x and y points using numpy. Plot x and y points over the plot, where x ticks could be from 1 to 10 (100 data points) on the curve. To add extra ticks, use xticks() method and increase the range of ticks to 1 to 20 from 1 to 10. To display the figure, use the show() method.
Considering the initial script, and the tips given by @BenBolker, I had to use:
axis(side = 1, at = c([all the ticks you want]))
in order to add the ticks
in the graph. Here's the final result:
# Cumulative Distribuition
pdf("g1_3.pdf")
plot(x = f$V2, y = cumsum(f$V1), log = "x", pch = 3,
xlab = "Frequency", ylab = "P(X <= x)", axes = FALSE)
ticks = c(1, 5, 10, 40, 150, 500, 1000)
axis(side = 1, at = ticks)
axis(side = 2)
abline(h = seq(0, 1, 0.2), v = ticks, col = "lightgray", lty = 3)
box()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With