From 279a1a2fc8ac6bb724e21e22a94a000acb6809c3 Mon Sep 17 00:00:00 2001 From: EasyChart Date: Mon, 3 Jun 2019 11:10:16 +0800 Subject: [PATCH] =?UTF-8?q?Update=20=E5=9B=BE3-5-1=20=E5=9D=A1=E5=BA=A6?= =?UTF-8?q?=E5=9B=BE.R?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...-1 \345\235\241\345\272\246\345\233\276.R" | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git "a/\347\254\2543\347\253\240_\347\261\273\345\210\253\346\257\224\350\276\203\345\236\213\345\233\276\350\241\250/\345\233\2763-5-1 \345\235\241\345\272\246\345\233\276.R" "b/\347\254\2543\347\253\240_\347\261\273\345\210\253\346\257\224\350\276\203\345\236\213\345\233\276\350\241\250/\345\233\2763-5-1 \345\235\241\345\272\246\345\233\276.R" index d5b4ed5..60ef671 100644 --- "a/\347\254\2543\347\253\240_\347\261\273\345\210\253\346\257\224\350\276\203\345\236\213\345\233\276\350\241\250/\345\233\2763-5-1 \345\235\241\345\272\246\345\233\276.R" +++ "b/\347\254\2543\347\253\240_\347\261\273\345\210\253\346\257\224\350\276\203\345\236\213\345\233\276\350\241\250/\345\233\2763-5-1 \345\235\241\345\272\246\345\233\276.R" @@ -1,11 +1,11 @@ -#EasyCharts团队出品,如有商用必究, -#如需使用与深入学习,请联系微信:EasyCharts +#EasyCharts鍥㈤槦鍑哄搧锛 +#濡傛湁闂淇涓庢繁鍏ュ涔狅紝鍙仈绯诲井淇★細EasyCharts library(ggplot2) library(scales) library(reshape) -#--------------------------------------(a)两年份对比--------------------------------------------------------------- +#--------------------------------------(a)涓ゅ勾浠藉姣--------------------------------------------------------------- df <- read.csv("Slopecharts_Data1.csv") colnames(df) <- c("continent", "1952", "1957") @@ -14,15 +14,15 @@ right_label <- paste(df$continent, round(df$`1957`),sep=", ") df$class <- ifelse((df$`1957` - df$`1952`) < 0, "red", "green") p <- ggplot(df) + - geom_segment(aes(x=1, xend=2, y=`1952`, yend=`1957`, col=class), size=.75, show.legend=F) + #连接线 - geom_vline(xintercept=1, linetype="solid", size=.1) + # 1952年的垂直直线 - geom_vline(xintercept=2, linetype="solid", size=.1) + # 1957年的垂直直线 - geom_point(aes(x=1, y=`1952`), size=3,shape=21,fill="grey80",color="black") + # 1952年的数据点 - geom_point(aes(x=2, y=`1957`), size=3,shape=21,fill="grey80",color="black") + # 1957年的数据点 + geom_segment(aes(x=1, xend=2, y=`1952`, yend=`1957`, col=class), size=.75, show.legend=F) + #杩炴帴绾 + geom_vline(xintercept=1, linetype="solid", size=.1) + # 1952骞寸殑鍨傜洿鐩寸嚎 + geom_vline(xintercept=2, linetype="solid", size=.1) + # 1957骞寸殑鍨傜洿鐩寸嚎 + geom_point(aes(x=1, y=`1952`), size=3,shape=21,fill="grey80",color="black") + # 1952骞寸殑鏁版嵁鐐 + geom_point(aes(x=2, y=`1957`), size=3,shape=21,fill="grey80",color="black") + # 1957骞寸殑鏁版嵁鐐 scale_color_manual(labels = c("Up", "Down"), values = c("green"="#A6D854","red"="#FC4E07")) + xlim(.5, 2.5) -# 添加文本信息 +# 娣诲姞鏂囨湰淇℃伅 p <- p + geom_text(label=left_label, y=df$`1952`, x=rep(1, NROW(df)), hjust=1.1, size=3.5) p <- p + geom_text(label=right_label, y=df$`1957`, x=rep(2, NROW(df)), hjust=-0.1, size=3.5) p <- p + geom_text(label="1952", x=1, y=1.02*(max(df$`1952`, df$`1957`)), hjust=1.2, size=5) @@ -31,7 +31,7 @@ p <- p + geom_text(label="1957", x=2, y=1.02*(max(df$`1952`, df$`1957`)), hjust= p<-p+theme_void() p -#-------------------------------------(b)多年份对比--------------------------------------------------------------------------------- +#-------------------------------------(b)澶氬勾浠藉姣--------------------------------------------------------------------------------- library(ggalt) df <- read.csv("Slopecharts_Data2.csv") @@ -90,4 +90,4 @@ p <- p + geom_text(label="2013", x=7, y=1.02*(max(df2$value)), hjust=-0.1, size= p<-p+theme_void()+ theme(legend.position = "none") -p \ No newline at end of file +p