[英]How can I mark all points with a given number property in coordinates?
我目前有这个R脚本:
library(ggplot2)
png("collatz-max-in-seq.png", width = 512, height = 800)
mydata = read.csv("../collatz-maxNumber.csv")
# Prepare data
p<-ggplot(mydata, aes(x=n, y=maximum))+ scale_y_continuous(formatter = "comma", limits = c(0, 100000))
p<-p + geom_point()
p<-p + opts(panel.background = theme_rect(fill='white', colour='white'))
# This will save the result in a pdf file called Rplots.pdf
p
dev.off()
如何将所有具有2的幂的点标记为x坐标?
如果无法进行此类检查,我还可以制作另一个带有所有x值且应被标记的csv文件。 请注意,我仍然要标记点,而不是x值本身。
这应该工作。 您要做的就是根据您的x
值是否为2的幂来添加一列颜色美感值。 在此示例中,“ n”是2的幂的所有行的取值为2,否则取值为1:
mydata$col <- ( sqrt(mydata$n) %% 1 == 0 ) + 1
然后可以将其绘制为
# Plot
ggplot( mydata , aes( x = n , y = maximum , colour = factor(col) ) )+
geom_point()+
scale_y_continuous( formatter = "comma" , limits = c( 0, 100000 ) )
一个实际的例子...
# Sample data
mydata <- data.frame( n = rep(1:9,4) , y = sample( 20 , 36 , repl = TRUE ) )
# Make the colour aesthetic
mydata$col <- ( sqrt(mydata$n) %% 1 == 0 ) + 1
# Plot!
ggplot( mydata , aes( x = n , y = y , colour = factor(col) ) )+
geom_point( )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.