Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 分别调整几何点()和几何线()_R_Ggplot2 - Fatal编程技术网

R 分别调整几何点()和几何线()

R 分别调整几何点()和几何线(),r,ggplot2,R,Ggplot2,我正在尝试使用ggplot创建一个简单的绘图。问题在于,生成的打印仅调整线型,而不显示点。下面是一个工作示例: a <- matrix(NA, ncol=2, nrow=9) a[,1] <- rnorm(9) a[,2] <- runif(9) colnames(a)<-c("first","second") a <- melt(a,id.vars=1:1) colnames(a)<-c("c", "variable", "value") b <

我正在尝试使用ggplot创建一个简单的绘图。问题在于,生成的打印仅调整线型,而不显示点。下面是一个工作示例:

a <- matrix(NA, ncol=2, nrow=9)
a[,1] <- rnorm(9)
a[,2] <- runif(9)

colnames(a)<-c("first","second")


a <- melt(a,id.vars=1:1)
colnames(a)<-c("c", "variable", "value")
b <- c("a","b","c","d","e","f","g","h","i","a","b","c","d","e","f","g","h","i")
f <- cbind(b,a)
f$variable <- factor(f$variable, levels=c("first", "second"))
colnames(f) <- c("b","c","variable","value")

ggplot(f, aes(x=b, y=value, colour=variable, size=variable, linetype=variable, group=variable)) + geom_point() + geom_line()+scale_colour_manual(values=c("blue3","red3"))+scale_linetype_manual(values=c(1,1))+scale_size_manual(values=c(0.3,0.3))+theme_bw()

a您的代码中有几个问题。首先,如果两条线都需要相同的线型(使用
scale\u linetype\u manual()
将它们设置为相同的类型),则不要在
aes()中使用
linetype=variable
。第二个问题是规模。您还可以在
ggplot()
aes()
中使用
size=variable
,然后使用
scale\u size\u manual()
再次使两个级别相同。如果size=变量位于
ggplot()
内,则会影响点和线的大小

geom_line()
geom_point()

ggplot(f, aes(x=b, y=value, colour=variable, group=variable)) + 
      geom_point(size=2) + geom_line(size=0.3)+
      scale_colour_manual(values=c("blue3","red3"))+
      theme_bw()

有没有办法将其中一条线的线型更改为虚线?我尝试将其输入到缩放线型手册(c(1,3))中,它仍将显示两条实线,您需要在
aes()
中使用
linetype=variable
,但不要使用具有相同值的
scale\u linetype\u manual()