[英]Displaying legend in a log-log plot using ggplot in R
I have the following code which plots the data in log-log plot, 我有以下代码以log-log图的形式绘制数据,
mp <- ggplot(cur_df,aes(x = Frequency, y = C_0V)) +
scale_x_log10(breaks = trans_breaks("log10", function(x) 10^x), labels = trans_format("log10", math_format(10^.x))) +
scale_y_log10(breaks = trans_breaks("log10", function(x) 10^x), labels = trans_format("log10", math_format(10^.x))) +
labs(x="t", y=expression ( bold(paste("J (A/", cm^2, ")", sep = "")) ) ) +
theme_bw() +
theme(axis.text=element_text(size=24)) +
theme(axis.title=element_text(size=20,face="bold"))+
annotation_logticks(sides = "trbl") +
theme(panel.grid.minor = element_blank()) +
geom_point() +
geom_point(data = cur_df, aes(y = C_ngv1V), colour = ' firebrick1', size = 1.5)
Mydata is the following, 以下是Mydata,
t C_0V C_ngv1V
10 3.72E-09 -4.88E-09
12.58925 3.63E-09 -2.16E-09
15.84893 3.71E-09 -1.35E-09
19.95262 3.47E-09 -1.43E-09
25.11887 3.33E-09 1.76E-09
31.62278 3.41E-09 1.54E-09
39.81072 3.44E-09 2.68E-09
50.11873 3.62E-09 2.18E-09
63.09575 3.32E-09 3.00E-09
79.43285 3.33E-09 3.30E-09
100 3.33E-09 3.32E-09
125.8926 3.30E-09 3.62E-09
158.4894 3.36E-09 3.72E-09
199.5263 3.33E-09 3.93E-09
251.1887 3.25E-09 3.96E-09
316.2279 3.22E-09 4.08E-09
398.1073 3.20E-09 4.10E-09
501.1874 3.23E-09 4.14E-09
630.9576 3.21E-09 4.09E-09
794.3286 3.16E-09 4.12E-09
1000 3.11E-09 4.05E-09
1258.926 3.03E-09 4.00E-09
1584.894 2.97E-09 3.90E-09
1995.263 2.89E-09 3.82E-09
2511.888 2.79E-09 3.71E-09
3162.28 2.69E-09 3.56E-09
3981.074 2.59E-09 3.41E-09
5011.875 2.50E-09 3.25E-09
6309.578 2.41E-09 3.10E-09
7943.288 2.32E-09 2.93E-09
10000.01 2.23E-09 2.76E-09
12589.26 2.15E-09 2.59E-09
15848.94 2.06E-09 2.43E-09
19952.64 1.97E-09 2.29E-09
25118.88 1.87E-09 2.16E-09
31622.8 1.77E-09 2.04E-09
39810.75 1.67E-09 1.93E-09
50118.77 1.56E-09 1.83E-09
63095.79 1.45E-09 1.72E-09
79432.89 1.35E-09 1.61E-09
100000.1 1.25E-09 1.48E-09
125892.6 1.16E-09 1.36E-09
158489.5 1.07E-09 1.22E-09
199526.4 9.66E-10 1.08E-09
251188.9 8.94E-10 9.53E-10
316228.1 8.24E-10 8.29E-10
398107.6 7.52E-10 7.12E-10
501187.8 6.74E-10 6.02E-10
630958 1.38E-10 4.89E-10
794329.1 7.42E-11 3.59E-10
1.00E+06 5.64E-11 1.92E-10
Now to display the legend, I use the following code but for some reason the legend is not displayed in the plot. 现在要显示图例,我使用以下代码,但由于某些原因,图例中未显示图例。
mp + theme(legend.position = 'right') mp + theme(legend.position ='right')
Could someone point out what should be corrected here to display the legend in the right side of the plot. 有人可以指出应该在此处更正的内容,以便在图的右侧显示图例。
When I plot mp it looks like this without any legend, 当我绘制mp时,它看起来像这样,没有任何图例,
我认为颜色和尺寸应该在Aes内
geom_point(data = cur_df, aes(y = C_ngv1V, colour = ' firebrick1', size = 1.5))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.