[R-SIG-Mac] Dashed line not evenly separated
Daniel Kelley
D@n@Ke||ey @end|ng |rom D@|@C@
Thu Feb 24 11:46:26 CET 2022
The other comments suggest that this problem is not unique to you. The mention of a different version of R suggests that this may be a long-standing problem.
If you really just need a plot, and cannot move that one task off onto a windows or linux machine, perhaps you could try something that may seem a bit "iffy", by subsampling the predictions of "x" and "y" at uniform x intervals, then plotting the results. You could then use lines() to draw this on top of your other plot, to check that you have enough intervals to capture the curve. Once you verify that you have enough subintervals to capture the function of interest, drop the plotting of the first line and plot the interpolated one, instead.
The key, obviously, is to make the subintervals of equal size in the final coordinate (in this case, in that log coordinate).
Supposing a typical plot of width 17 cm, and using 500 subintervals, the intervals would be under a line width, and therefore are likely to trace your function to a acceptable tolerance.
The following test code shows (for a made-up function) that results should retain the "dashed" character if you keep the number of subintervals fairly small (change n to 1e4 and we see the solidification problem at the peaks).
n <- 1e3 # try also 1e4, which solidifies at peaks
x <- seq(0,2*pi,length.out=n)
y <- sin(x)
plot(x,y,type="l", lty=2)
On Feb 23, 2022, at 6:41 PM, Zhang, Jialin via R-SIG-Mac <r-sig-mac using r-project.org<mailto:r-sig-mac using r-project.org>> wrote:
CAUTION: The Sender of this email is not from within Dalhousie.
Hello Mac experts,
I wrote the following code on my Mac but the resulting plot has a weird dashed line. Here are the codes:
zeta.ppt <- function(v){
ppt=function(i){
result <- numeric(length(i))
for (j in i){
if (j < 11) {result[j] <- (11-j)/110}
else {result[j] <- 3/pi^2/(j-10)^2}
}
result
}
p <- ppt(1:10000)
printout <- numeric(length(v))
for (k in 1:length(v)) {
printout[k] <- sum(p*(1-p)^v[k])
}
printout
}
zeta.sept <- function(v){
sept=function(i){
result <- numeric(length(i))
for (j in i){
if (j < 11) {result[j] <- (11-j)/110}
else {result[j] <- 0.5/1.670407*exp(-sqrt(j-10))}
}
result
}
p <- sept(1:10000)
printout <- numeric(length(v))
for (k in 1:length(v)) {
printout[k] <- sum(p*(1-p)^v[k])
}
printout
}
tau.ppt <- function(v){
v*zeta.ppt(v)
}
tau.sept <- function(v){
v*zeta.sept(v)
}
plot(log(tau.ppt(1:20000))~log(1:20000), xlim = c(0,10), ylim=c(0, 5), axes = F, ylab = "", xlab = "", type = "l")
lines(log(tau.sept(1:20000))~log(1:20000), lty = 2, type = "l")
box()
Here is the plot I got:
<image001.png>
As we could observe, the end portion of the dashed line is almost a solid line. I posted the question onhttps://stackoverflow.com/questions/71241028/plot-line-types-in-r as well and seems they can run my codes with perfect dashed line on Windows OS.
I have tried it on both intel Mac and M1 Mac, both gave me weird dashed lines. I have tried it in both R and RStudio. Here is my sessionsInfo:
> sessionInfo()
R version 4.1.2 (2021-11-01)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Monterey 12.2.1
Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_4.1.2 tools_4.1.2
Please advise. Thank you!
—
Jialin Zhang (JZ), Assistant Professor of Statistics
Department of Mathematics and Statistics
Mississippi State University
tel: (662) 325-7137; email: jzhang using math.msstate.edu<mailto:jzhang using math.msstate.edu>
_______________________________________________
R-SIG-Mac mailing list
R-SIG-Mac using r-project.org<mailto:R-SIG-Mac using r-project.org>
https://stat.ethz.ch/mailman/listinfo/r-sig-mac
[[alternative HTML version deleted]]
More information about the R-SIG-Mac
mailing list