[英]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.