本文介绍了用ggplot2绘制一个使用整数值的阿基米德螺线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 你怎么在R里画漩涡?我试图绘制一个数字列表1:100 ,并且每7个数字将其分配一个因子'1',其他所有其他'0'。我也有一个TRUE或FALSE向量。我如何绘制这些数字的漩涡并突出每第七个数字?试着看看我是否可以拧紧或松开旋涡(theta)以对齐第7个数字。以下用于创建数据的代码。我使用了两种不同的功能来查看哪种矢量最适合。逻辑向量或1或0的向量。 returnint< - function(x){ if(x == TRUE){ return (1)} else { return(0)} } isseven if (x %% 7){ return(0)#FALSE } else { return(1)#TRUE } } fo = seq(1,100) fo.sev = NULL#因子 fo.int = NULL#as int 0 = FALSE,1 = TRUE for i in 1:length(fo)){ fo.sev [i] = as.logical(isseven(i)) fo.int [i] = returnint(fo.sev [i]) df< - data.frame(fo,fo.int,as.factor(fo.sev)) names(df)< - c(x,intx,seven) df 解决方案(我承认回答标题中的要求,但不理解其他文本的要求,尽管后来我猜测了一下。)只需要用一对参数方程: x = t * cos(t); y = t * sin(t) 您需要实例化 t 很好......如果你的目的是一条平滑的曲线: $ $ $ $ $ $ $ $ $ $ $ t $ seq(0, 10,by = 0.01)x = t * cos(t); y = t * sin(t) ggplot(data.frame(x,y),aes(x = x,y = y))+ geom_path() 这是对什么的猜测被要求绘制整数; png() print(ggplot(df,aes(x = x * cos(x),y = x * sin(x)))+ geom_label(data = df,aes(label = x,color = intx,size = intx + 1))+ coord_equal )) dev.off() 它确实出现了标签框的最小尺寸,因为即使它们的尺寸是零。我确实用 label.padding = unit(0.05,lines) 得到了更小的标签框How do you draw a swirl in R ? I am trying to plot a list of numbers 1:100and every 7th number assign it a factor '1' all others just '0' . I also have a vector of TRUE or FALSE . How do I plot a swirl of these numbers and highlight every seventh number ? Trying to see if I can tighten or loosen the swirl (theta) to align the 7th numbers. The following code I used to create the data. I used two different functions just to see which vector would work best. A logical vector or a vector of "1" or "0" 's . returnint <- function( x ) { if ( x == TRUE) { return (1) } else { return (0) } }isseven <- function( x ) {if (x %% 7) { return (0) # FALSE } else { return (1) # TRUE }}fo = seq(1, 100)fo.sev = NULL # factorsfo.int = NULL # as int 0 = FALSE , 1 = TRUEfor (i in 1:length(fo)) { fo.sev[i] = as.logical(isseven(i)) fo.int[i] = returnint(fo.sev[i])}df <- data.frame(fo,fo.int,as.factor(fo.sev))names(df) <- c("x","intx","seven")df 解决方案 (I admit to answering the request in the title, but not understanding what the rest of your text was requesting, although I later took a guess.) Just set up data with a pair of parametric equations:x = t*cos(t); y = t*sin(t)You need to instantiate t finely enough ... if your purpose is a smooth curve: t <- seq(0, 10, by=0.01) x = t*cos(t); y = t*sin(t) ggplot(data.frame(x,y), aes(x=x,y=y))+geom_path()This is a guess at what was requested for plotting the integers;png() print( ggplot( df, aes(x=x*cos(x), y=x*sin(x))) + geom_label(data=df, aes(label=x, color=intx, size=intx + 1) ) + coord_equal() ) dev.off()It did appear that the label boxes had a minimum size, since they appeared visible even when their size was zero. And I did get smaller "label boxes" with label.padding = unit(0.05, "lines") 这篇关于用ggplot2绘制一个使用整数值的阿基米德螺线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-18 17:25