首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

#ggplot2

ggplot2 如何将双x轴显示在底部?

R语言ggplot2 如何添加第二x轴?

ggplot2我想要的就是将y轴向右移动,并将它们向左对齐,以将它们包含在条形图中?

ggplot2如何单独设置拟合线条的图例?

请问如何用ggplot2使图表中的文字方向有的水平有的垂直有的45度?

如何用ggplot2同时让图中标签文字的方向各不相同?

在ggplot2中,如何添加额外的图例?

不不个了路遙知馬力 日久見人心。
已采纳
我并不是100%确定这是你想要的,但是我知道这是我如何处理这个问题。如果我们将一些geom使用的数据映射到图上xx.sub1.df,但是使其在图上不可见,我们仍然可以得到一个图例。在这里我已经使用过geom_point,但你可以让它成为别人。代码: p <- ggplot(xx.sub2.df) + aes(long, lat, fill = (SID79/BIR79)*1000, group = group) + geom_polygon() + geom_path(color="grey80") + coord_equal() + scale_fill_gradientn(colours = brewer.pal(7, "YlOrBr")) + geom_polygon(data = xx.sub1.df, fill = "grey50") + geom_path(data = xx.sub1.df, color="grey80") + labs(fill = "Mapped value", title = "Title") #Now we add geom_point() setting shape as NA, but the colour as "grey50", so the #legend will be displaying the right colour p2 <- p + geom_point(data = xx.sub1.df, aes(size="xx.sub1", shape = NA), colour = "grey50") 📷 现在我们只需要改变图例上点的大小和形状,并更改图例的名称: p2 + guides(size=guide_legend("Source", override.aes=list(shape=15, size = 10))) 📷 当然,你可以更改标签的工作方式或其他方式来突出显示你想要展示的内容。 ... 展开详请

如何制作xkcd风格的图表?

秋之夕颜清念念不忘,必有回响
基本的画线功能: xkcd_line <- function(x, y, color) { len <- length(x); rg <- par("usr"); yjitter <- (rg[4] - rg[3]) / 1000; xjitter <- (rg[2] - rg[1]) / 1000; x_mod <- x + rnorm(len) * xjitter; y_mod <- y + rnorm(len) * yjitter; lines(x_mod, y_mod, col='white', lwd=10); lines(x_mod, y_mod, col=color, lwd=5); } 基本轴: xkcd_axis <- function() { rg <- par("usr"); yaxis <- 1:100 / 100 * (rg[4] - rg[3]) + rg[3]; xaxis <- 1:100 / 100 * (rg[2] - rg[1]) + rg[1]; xkcd_line(1:100 * 0 + rg[1] + (rg[2]-rg[1])/100, yaxis,'black') xkcd_line(xaxis, 1:100 * 0 + rg[3] + (rg[4]-rg[3])/100, 'black') } 和示例代码: data <- data.frame(x=1:100) data$one <- exp(-((data$x - 50)/10)^2) data$two <- sin(data$x/10) plot.new() plot.window( c(min(data$x),max(data$x)), c(min(c(data$one,data$two)),max(c(data$one,data$two)))) xkcd_axis() xkcd_line(data$x, data$one, 'red') xkcd_line(data$x, data$two, 'blue')... 展开详请

在ggplot2中如何旋转和放置轴标签?

秋之夕颜清念念不忘,必有回响

要使刻度标签上的文本完全可见并以与y轴标签相同的方向读取,请将最后一行更改为

代码语言:txt
复制
q + theme(axis.text.x=element_text(angle=90, hjust=1))
领券